1.將文件放到linux上使用less命令查看: less xxx.txt
2.去掉多余的字符
1)In your terminal, open the file using vim: vim file_name 2) Remove all BOM characters: :set nobomb 3) Save the file: :wq
3.搜索含有 bom 的文件命令:
grep -r -I -l $'^\xEF\xBB\xBF' ./
也可以用 nkf 檢查文件編碼 :nkf --guess */* | grep BOM
-j : 轉換為 JIS 編碼(ISO-2022-JP),默認 -e : 轉換為 EUC 編碼 -s : 轉換為 Shift-JIS 編碼 -w : 轉換為 UTF-8 編碼(無BOM) -Lu : 轉換為 unix 換行格式(LF) -Lw : 轉換為 windows 換行格式(CRLF) -Lm : 轉換為 macintosh 換行格式(CR) -g(--guess) : 自動判斷編碼並顯示 --version : 顯示版本 --help : 顯示幫助
linux中轉換成window : nkf -sxLw nkf -swLw
window轉換成linux : nkf -wxLu
$nkf -w myfile.txt >> test
這個命令的意思就是把文件myfile.txt文件文本的內容轉換成utf8的編碼然后輸出到文件test中