2019-04-21 11:50:48 +08:00

23 lines
1.5 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<h1 id="iconv">iconv</h1>
<p>转换文件的编码方式</p>
<h2 id="补充说明">补充说明</h2>
<p><strong>iconv命令</strong> 是用来转换文件的编码方式的比如它可以将UTF8编码的转换成GB18030的编码反过来也行。JDK中也提供了类似的工具native2ascii。Linux下的iconv开发库包括iconv_open,iconv_close,iconv等C函数可以用来在C/C++程序中很方便的转换字符编码这在抓取网页的程序中很有用处而iconv命令在调试此类程序时用得着。</p>
<h3 id="语法">语法</h3>
<pre><code class="language-bash">iconv -f encoding [-t encoding] [inputfile]... </code></pre>
<h3 id="选项">选项</h3>
<pre><code class="language-bash">-f encoding :把字符从encoding编码开始转换。
-t encoding :把字符转换到encoding编码。
-l :列出已知的编码字符集合
-o file :指定输出文件
-c :忽略输出的非法字符
-s :禁止警告信息,但不是错误信息
--verbose :显示进度信息
-f和-t所能指定的合法字符在-l选项的命令里面都列出来了。 </code></pre>
<h3 id="实例">实例</h3>
<p>列出当前支持的字符编码: </p>
<pre><code class="language-bash">iconv -l </code></pre>
<p>将文件file1转码转后文件输出到fil2中 </p>
<pre><code class="language-bash">iconv file1 -f EUC-JP-MS -t UTF-8 -o file2 </code></pre>
<p>这里,没<code>-o</code>那么会输出到标准输出。</p>
<!-- Linux命令行搜索引擎https://jaywcjlove.github.io/linux-command/ -->