查看文件编码格式

How can I see which encoding is used in a file? (查看文件编码格式)

  • vi模式下
查看
:set fileencoding
设置
:set fileencoding xxx  
  • file命令:
    1. check a file encoding
    file -bi [filename]
    
OptionDescription
-b, --briefDon’t print filename (brief mode)
-i, --mimePrint filetype and encoding
  1. change a file fileencoding
$ iconv -f [encoding] -t [encoding] -o [newfilename] [filename]
OptionDescription
-f, --from-codeConvert a file’s encoding from charset
-t, --to-codeConvert a file’s encoding to charset
-o, --outputSpecify output file (instead of stdout)

Change a file’s encoding from CP1251 (Windows-1251, Cyrillic) charset to UTF-8:

$ iconv -f cp1251 -t utf-8 in.txt

Change a file’s encoding from ISO-8859-1 charset to and save it to out.txt:

$ iconv -f iso-8859-1 -t utf-8 -o out.txt in.txt

Change a file’s encoding from ASCII to UTF-8:

$ iconv -f utf-8 -t ascii -o out.txt in.txt

Change a file’s encoding from UTF-8 charset to ASCII:

llegal input sequence at position: As UTF-8 can contain characters that can’t be encoded with ASCII, the iconv will generate the error message “illegal input sequence at position” unless you tell it to strip all non-ASCII characters using the -c option.

$ iconv -c -f utf-8 -t ascii -o out.txt in.txt

You can lose characters: Note that if you use the iconv with the -c option, nonconvertible characters will be lost.

  1. List All charsets
    List all the known charsets in your Linux system:
 iconv -l
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值