The Iconv command is a file-encoded reload tool that runs on the Linux/unix platform. When we look at the text file in the Linux/unix system shell, we often find that the file is garbled in Chinese, this is due to the encoding of the text file and the current operating system settings, which can be encoded by using the ICONV conversion, to solve the garbled problem.
resolving text file garbled problem is divided into 3 steps: 1. Determine the file encoding, 2. Determine whether Iconv supports this encoding conversion, 3. Determine Linux/unix operating system encoding, 4. The conversion file is encoded in accordance with the system code; The following is an example of a test.txt file.
1. Use the file command to determine the encoding:
$ file-bi gbk.txt | sed-e ' s/.*[]charset=//' |tr ' [A-z] ' [A-z]
iso-8859-1
the visible test.txt file encoding is ISO-8859-1 encoded.
2. Use Iconv-l to determine whether ICONV supports this type of encoding conversion:
$ iconv-l | grep iso-8859-1
iso-8859-1//
iso-8859-10//
iso-8859-11//
iso-8859-13//
iso-8859-14//
iso-8859-15//
iso-8859-16//
3. Determine the Linux/unix operating system code:
$ echo $LANG
ZH_CN. UTF-8
current operating system bad Environment code is "UTF-8"
4. Conversion Code
$ iconv-f iso-8859-1-T UTF-8 test.txt
Test
Note: Because the file command often misjudged the code, such as the discovery of the converted encoding is still garbled, you can change the input code of ICONV-F to other common coding test: GBK, BIG5, HZ, GB2312, GB18030, ASCII
detailed syntax for the ICONV command:
iconv [options:] File
Options:
- F Input Encoding
- t output encoding
-l list all known encodings
- o output file
Using Iconv command to deal with Chinese garbled characters of text files under Linux/unix system