iconv批量转换字符集编码的利器
前些天,一个客户提供了一个CSV文件,说导入MySQL失败,文件在2G左右,后来测试知道是Unicode(UTF-16LE)格式的缘故,用UltraEdit打开另存为UTF8格式,再次导入成功。不过对于这样大的文件,Ultraedit打开就颇为吃力了,如果文件再大的话就更困难了,于是想到可以使用另外一个利器来做字符集编码的转换,iconv。
网上有很多windows的编译版本,我这里提供的是利用mxe编译的静态win32版本,
下载地址:iconv-1.14-win32
iconv是一个计算机程序以及一套应用程序编程接口的名称。它的作用是在多种国际编码格式之间进行文本内码的转换。支持的内码包括:
作为应用程序的iconv采用命令行界面,允许将某种特定编码的文件转换为另一种编码。
用法,
Usage: iconv.exe [OPTION...] [-f ENCODING] [-t ENCODING] [INPUTFILE...]
or: iconv.exe -l
Converts text from one encoding to another encoding.
Options controlling the input and output format:
-f ENCODING, --from-code=ENCODING
the encoding of the input
-t ENCODING, --to-code=ENCODING
the encoding of the output
Options controlling conversion problems:
-c discard unconvertible characters
--unicode-subst=FORMATSTRING
substitution for unconvertible Unicode characters
--byte-subst=FORMATSTRING substitution for unconvertible bytes
--widechar-subst=FORMATSTRING
substitution for unconvertible wide characters
Options controlling error output:
-s, --silent suppress error messages about conversion problems
Informative output:
-l, --list list the supported encodings
--help display this help and exit
--version output version information and exit
Report bugs to <bug-gnu-libiconv@gnu.org>.
例子,
文件infile从UTF-16LE编码转换至UTF-8编码并写入到文件outfile中:
iconv -f UTF-16LE -t utf-8 infile > outfile
另外提供一个下载地址gettext-iconv-windows。