文件编码查看、转换

2023-05-15  本文已影响0人  十毛tenmao

文本文件都有编码格式,常见格式有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

参考

上一篇下一篇

猜你喜欢

热点阅读