How to convert the internal code of a text file in Linux [zz]

Source: Internet
Author: User

There are a lot of software in Windows that can be used to convert the file encoding, such as converting big5 to gb2312

This can also be done in Linux.

This command is iconv.

For example, to convert the foo.txt file in gb2312format to the big5 internal code, you can use

Iconv-F gb2312-T big5 foo.txt> foo1.txt

This new file foo1.txt is the big5 internal code.

Convert the big5's foo.txt file to the gb2312 internal code

Iconv-F big5-T gb2312 foo.txt> foo2.txt

Convert the gb2312 internal code file into a UTF-8

Iconv-F gb2312-T UTF-8 foo.txt> foo3.txt

Finally, batch conversion is used to convert all the files in a directory into the internal code we need.

Foo1.txt foo2.txt foo3.txt... foon.txt is the internal code of gb2312.

Make a special trip to big5, and add big5 as the suffix.

Create a script gb2312_2_big5.sh with the following content:

Ls *. txt | while read I

Do iconv-F gb2312-T big5 $ I >$ I. big5

Done

Save and run

Sh gb2312_2_big5.sh

To complete the conversion.

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.