Best way to convert text files between character sets?

后端 未结 21 2080
再見小時候
再見小時候 2020-11-22 04:42

What is the fastest, easiest tool or method to convert text files between character sets?

Specifically, I need to convert from UTF-8 to ISO-8859-15 and vice versa.

21条回答
  •  -上瘾入骨i
    2020-11-22 05:04

    Try VIM

    If you have vim you can use this:

    Not tested for every encoding.

    The cool part about this is that you don't have to know the source encoding

    vim +"set nobomb | set fenc=utf8 | x" filename.txt
    

    Be aware that this command modify directly the file


    Explanation part!

    1. + : Used by vim to directly enter command when opening a file. Usualy used to open a file at a specific line: vim +14 file.txt
    2. | : Separator of multiple commands (like ; in bash)
    3. set nobomb : no utf-8 BOM
    4. set fenc=utf8 : Set new encoding to utf-8 doc link
    5. x : Save and close file
    6. filename.txt : path to the file
    7. " : qotes are here because of pipes. (otherwise bash will use them as bash pipe)

提交回复
热议问题