Solution to garbled characters in ubuntu

Source: Internet
Author: User
Solution for garbled characters in ubuntu: The txt file can be normally displayed in Windows, and the file garbled characters can be opened in Ubuntu. This is a Chinese encoding problem. in Windows, gb2312 is used, while in linux, utf8 is used. Five solutions are provided here: 1. run the command www.2cto in the directory where the document is located...
Solution for garbled characters in ubuntu: The txt file can be normally displayed in Windows, and the file garbled characters can be opened in Ubuntu. This is a Chinese encoding problem. in Windows, gb2312 is used, while in linux, utf8 is used. Five solutions are provided here:
1. run the command www.2cto.com iconv-f gb2312-t utf8-c 1.txt> 2.txt option-c in the directory where the document is located to ignore unrecognized characters and continue backward conversion. Otherwise, iconv terminates the conversion if it encounters an unrecognized character. Iconv cannot implement batch Conversion. you need to write a small program to achieve this purpose. 2. run the command to open the txt file using gedit. the default gedit encoding is UTF8. the gb2312 files edited in windows are garbled. {the default file format in Windows is GBK (gb2312 ), (GBK encoding is a superset of GB2312 encoding and is fully compatible with GB2312 .)}. The solution is to change the default gedit encoding to GB2312. Gconf-editor then click on: apps-> gedit-2-> preferences-> encodings double-click auto-detected in encodings add GB2312 in the pop-up dialog box, move GB2312 to the top, exit. 3. open it with openoffice. FILE-open the txt file you want to open. when it is opened, a window will pop up asking you what types of characters to select. Select Simplified Chinese (GB18030). (GB18030 is backward compatible with GBK and GB2312. compatibility means not only character compatibility, but also the same character encoding .) It will be displayed normally. Just ask every time 4. complete the conversion from gbk to uft-8 on Windows, the effect is better than method 1. The specific method is as follows: F: \ corpus \ tc-corpus-train \ train> for/r C4-Literature % I in (*. txt) do iconv.exe-f gbk-t UTF-8 % I> % ~ Ni.txt 5. use enca. Enca can automatically identify the encoding type of the original file, and supports wildcards to achieve batch conversion. Enca-L original file language type-x target encoding original file name example: enca-L zh_CN-x UTF-8 file.txt but enca will often encounter conversion failure, of course, an error report is provided for enca that cannot be converted.

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.