文本文件都有编码格式,常见格式有UTF8、GBK、latin1等,因为编码不统一,所以在文件处理的时候经常会遇到编码导致的乱码问题
$ file utf8_hello.txt
utf8_hello.txt: UTF-8 Unicode text
iconv -f src_encoding -t target_encoding inputfile -o outputfile
# 把utf8编码的文件utf8_hello.txt转换为gbk编码的gbk_hello.txt
iconv -f utf-8 -t gbk utf8_hello.txt -o gbk_hello.txt
## 使用gbk编码打开文件file.txt
vim file.txt -c "e ++enc=gbk"
File -> Reopen with Encoding