Using Iconv command to deal with Chinese garbled characters of text files under Linux/unix system

Source: Internet
Author: User

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]
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
3. Determine the Linux/unix operating system code:
$ echo $LANG
current operating system bad Environment code is "UTF-8"
4. Conversion Code
$ iconv-f iso-8859-1-T UTF-8 test.txt
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
- 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.