File encoding format conversion under Linux

Source: Internet
Author: User

Recently put the project on GitHub, but found the code in the Chinese part of the comments are garbled, after the check found that because my CentOS installed on the virtual machine, and I am in the Windows environment through the UE to write code, and UE by default, using ASCII encoding.

So you want to use commands on Linux to convert the encoding format in bulk.

After checking the data, we found that the iconv command can be used.

First, use the file command to detect the type of files

Example:filetest.cpp

Output:ISO-8859 Cprogram text

Parameter description of the iconv command:

- l List all known character sets

- F Raw Text encoding

- t output text encoding

- o output file name

- s off warning

Example:

iconv-f gb2312-t UTF-8 test.cpp > Test_utf.cpp

Because Iconv is output to standard output by default, we need to redirect to a different file. (This cannot be redirected to itself, otherwise the contents of the file will be emptied)

If you want to output the output directly to the current file, you can use the following:

iconv-f gb2312-t UTF-8-o test.cpp test.cpp

File encoding format conversion under Linux

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: info-contact@alibabacloud.com 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.