如果 enca 命令不存在,使用brew 安装即可:
Rockmbp:account.txt2 rock$ brew install enca
使用 enca 命令查看当前文件是什么编码,如下:
Rockmbp:account.txt2 rock$ enca 0915-500.txt Simplified Chinese National Standard; GB2312 CRLF line terminators ## 转码前参考: Rockmbp:account.txt2 rock$ grep "861845x345484" 0915-500.txt | awk -F '###' '{print $(NF-2) "----" $(NF-1)}' ����:1982.3.11----ע��ʱ��:2016/9/13 2:11:42
使用 iconv 命令转换到需要的编码:
iconv -f GB2312 -t UTF-8 0915-500.txt > utf8-0915-500.txt ##检查结果: Rockmbp:account.txt2 rock$ enca utf8-0915-500.txt Universal transformation format 8 bits; UTF-8 CRLF line terminators ## 转码后参考: Rockmbp:account.txt2 rock$ grep "861845x345484" utf8-0915-500.txt | awk -F '###' '{print $(NF-2) "----" $(NF-1)}' 生日:1982.3.11----注册时间:2016/9/13 2:11:42