2015年6月23日 星期二

【備忘】用 iconv 來轉換文字編碼

在 Linux 下閱讀簡體字的文件時,可以先透過 iconv 來轉換文字編碼,避免用文字編輯器打開檔案時呈現亂碼

iconv 的說明:
NAME
       iconv - Convert encoding of given files from one encoding to another

SYNOPSIS
       iconv -f encoding [-t encoding] [inputfile]...

DESCRIPTION
       The iconv program converts the encoding of characters in inputfile, or from the standard input if no filename is specified, from one coded character set to another. The result is
       written to standard output unless otherwise specified by the --output option.

       --from-code, -f encoding
              Convert characters from encoding.

       --to-code, -t encoding
              Convert characters to encoding. If not specified the encoding corresponding to the current locale is used.

       --list, -l
              List known coded character sets.

       -c     Omit invalid characters from output.

       --output, -o file
              Specify output file (instead of stdout).

       --silent, -s
              Suppress warnings, but not errors.

       --verbose
              Print progress information.

       --help, -?
              Give help list.

       --usage
              Give a short usage message.

       --version, -V
              Print program version.
假設來源檔案為 source.txt,轉換成 utf-8 後的檔名叫 target.txt,那麼就在命令列輸入下列內容:
iconv -f gb2312 -t utf-8 source.txt --output target.txt
搞定收工!

沒有留言: