Problem:
When users want to browse file, but finding the garbled code(亂碼) in the file.
Occurrence opportunity:
Mostly happen in file conversion from different O.S because Windows default encoding system is BIG-5, and MacOS’s is UTF-8.
Supplement:
BIG5 與GB2312 是繁體中文與簡體中文最常採用的ANSI 形式編碼
Solution:
- User need manually to convert the script or file, even finding specific software to solve with it.
- Typing instructions in command line (Terminal in Linux and MacOS; DOS in Windows) —> I will introduce manners in this case.
There are two instructions, one is enca, the other is iconv, can resolve this issue.
First,
enca
Synopsis:
enca [-L LANGUAGE] [OPTION]... [FILE]...
Instruction:
enca -L zh_CN file_name //檢查文件的編碼
enca -L zh_CN -x UTF-8 file_name //將文件編碼轉換為“UTF-8”編碼
enca -L zh_CN -x UTF-8 file2_name //如果不想覆蓋原文件可以這樣
parameter:
-x means convert to, and zh_CN means Chinese encoding.
Second,
iconv
Synopsis:
iconv [OPTION...] [-f encoding] [-t encoding] [inputfile ...]
Instruction:
iconv -f BIG-5 UTF-8 big5.txt > utf8.txt
parameter
-f encoding, --from-code=encoding
發表留言