RHEL9 iconvコマンドでファイルの文字コードを変換する

環境
Red Hat Enterprise Linux release 9.2 (Plow)

書式
iconv [オプション] [入力ファイル]

概要
iconvコマンドは、指定した入力ファイルの文字コードを変換するコマンドです。

オプション
-c 変換できなかった文字を出力から除きます。
-f 文字コード 変換前の文字コード(エンコーディング)を指定します。
-l 文字コードの一覧を表示します。
-o 出力ファイル 出力ファイルを指定します。
-t 文字コード 変換後の文字コード(エンコーディング)を指定します。

使用例
1.文字コードに一覧を表示します(オプション -l)。コマンドを実行するとやたらと多くの文字コードが表示されます。

# iconv -l
The following list contains all the coded character sets known.  This does
not necessarily mean that all combinations of these names can be used for
the FROM and TO command line parameters.  One coded character set can be
listed with several different names (aliases).

  437, 500, 500V1, 850, 851, 852, 855, 856, 857, 858, 860, 861, 862, 863, 864,
  865, 866, 866NAV, 869, 874, 904, 1026, 1046, 1047, 8859_1, 8859_2, 8859_3,
  8859_4, 8859_5, 8859_6, 8859_7, 8859_8, 8859_9, 10646-1:1993,
  10646-1:1993/UCS4, ANSI_X3.4-1968, ANSI_X3.4-1986, ANSI_X3.4,
  ANSI_X3.110-1983, ANSI_X3.110, ARABIC, ARABIC7, ARMSCII-8, ARMSCII8, ASCII,
  ASMO-708, ASMO_449, BALTIC, BIG-5, BIG-FIVE, BIG5-HKSCS, BIG5, BIG5HKSCS,
  略

2.UTF-8 のテキストファイル「test.txt」を EUC-JP に変換し、ファイル「result.txt」に出力します。
$ iconv -f UTF-8 -t EUC-JP test.txt -o result.txt

IT

Posted by arkgame