1. If you need to operate files in Windows in Linux, you may frequently encounter file encoding conversion problems. In Windows, the default file format is GBK (gb2312), while Linux is generally a UTF-8.
2. You can view the file encoding in vim.
: Set fileencoding
Solve the problem of using Vim to View File garbled characters.
~ /. Add the following content to vimrc:
Set encoding = UTF-8 fileencodings = ucs-bom, UTF-8, cp936
3. file encoding and conversion
1) convert the file encoding directly in Vim. For example, convert a file to UTF-8 format.
: Sets fileencoding = UTF-8
2) enconv conversion file encoding, such as to convert a GBK encoded file into UTF-8 encoding:
Enconv-l zh_cn-x UTF-8 filename
3) iconv conversion. The iconv command format is as follows:
Iconv-F encoding-T encoding inputfile
For example, converting a UTF-8-encoded file into GBK Encoding
Iconv-F UTF-8-t gbk file1-O file2
4. iconv options
①-C: Ignore invalid characters from the output
②-O, -- output = file: output file
③-F, -- from-code = Name Original Text Encoding
④-T, -- to-code = Name output Encoding
⑤-L, -- list lists all known character sets
⑥-- Usage provides brief usage information
5. batch conversion [4]
Assume that foo1.txt foo2.txt... foon.txt is a gb2312 internal code, and all of them are specially made into the big5 internal code, and big5 is added 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
Reference
[1] viewing file encoding formats and file encoding conversion in Linux
Http://blog.csdn.net/jznhljg/article/details/3410750
[2] This article describes the C language library version of iconv, which is worth reading.
Http://550480286.blog.163.com/blog/static/990932472010102451858555/
Http://qq164587043.blog.51cto.com/261469/63349
[3] describes the options in detail.
Http://www.cnblogs.com/morebetter/archive/2005/05/28/164099.html
[4] batch conversion
Http://init7.blog.51cto.com/860934/182003