Mac上如何查看及转换文件编码

2023-03-20 11:13:30
标签: --mime-encoding iconv od hexdump

这次做性能测试,结果文件是xml,但是antlr读取好像遇到问题,于是查看编码

conanchen@ConanChen ~ % file --mime-encoding /Users/conanchen/Desktop/PerformanceReport/2.1.284_macOS\ 13.0_20230317183825_PerformanceResult.xml

/Users/conanchen/Desktop/PerformanceReport/2.1.284_macOS 13.0_20230317183825_PerformanceResult.xml: utf-16le

conanchen@ConanChen ~ % iconv -f utf-16le -t utf-8 /Users/conanchen/Desktop/PerformanceReport/2.1.284_macOS\ 13.0_20230317183825_PerformanceResult.xml >> utf-8.xml

conanchen@ConanChen ~ % file --mime-encoding utf-8.xml

utf-8.xml: utf-8

用iconv就能把文件转换格式。

用od或hexdump可以显示出文件头内容

conanchen@ConanChen ~ % od -Ax -t x1 -N 16 /Users/conanchen/utf-8.xml

0000000 ef bb bf 3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e

0000010

conanchen@ConanChen ~ % od -Ax -t x1 -N 16 /Users/conanchen/Desktop/PerformanceReport/2.1.284_macOS\ 13.0_20230317183825_PerformanceResult.xml

0000000 ff fe 3c 00 3f 00 78 00 6d 00 6c 00 20 00 76 00

0000010

conanchen@ConanChen ~ % od -Ax -j 10 -t x1 -N 6 /Users/conanchen/Desktop/PerformanceReport/2.1.284_macOS\ 13.0_20230317183825_PerformanceResult.xml

000000a 6c 00 20 00 76 00

0000010

-j 可以跳过前面N个字节


阅读(0) 收藏(0) 转载(0) 举报/Report
相关阅读

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有