iconv命令

iconv命令:

Convert encoding of given files from one encoding to another,更改文件的编码格式

语法格式:

iconv -f encoding -t encoding inputfile

常用选项:

-f encoding :把字符从encoding编码开始转换
-t encoding :把字符转换到encoding编码

-l 列出已知的编码字符集合 

-o file :指定输出文件 

-c :忽略输出的非法字符 

-s :禁止警告信息,但不是错误信息

实例:

[root@www1 ~]# iconv test.txt -f UTF-8 -t gbk
▒▒һ▒▒
▒ڶ▒▒▒
▒▒▒▒▒▒
▒▒▒▒▒▒
▒▒▒▒▒▒
▒▒▒▒▒▒
▒▒▒▒▒▒
You have mail in /var/spool/mail/root
[root@www1 ~]# iconv test.txt -c -f UTF-8 -t gbk
▒▒һ▒▒
▒ڶ▒▒▒
▒▒▒▒▒▒
▒▒▒▒▒▒
▒▒▒▒▒▒
▒▒▒▒▒▒
▒▒▒▒▒▒
[root@www1 ~]# iconv test.txt -c -f UTF-8 -t gbk -o testt.txt
You have mail in /var/spool/mail/root
[root@www1 ~]# cat testt.txt
▒▒һ▒▒
▒ڶ▒▒▒
▒▒▒▒▒▒
▒▒▒▒▒▒
▒▒▒▒▒▒
▒▒▒▒▒▒
▒▒▒▒▒▒


猜你喜欢

转载自blog.51cto.com/12107790/2139092
今日推荐