iconv Command

Purpose

Converts the encoding of characters from one code page encoding scheme to another.

Syntax

iconv [-cs] -f FromCode -t ToCode [ FileName... ]

iconv -l

Description

The iconv command converts the encoding of characters read from either standard input or the specified file from one coded character set to another and then writes the results to standard output. The input and output coded character sets are identified by the FromCode and ToCode parameters. The input data should consist of characters in the code set specified by the FromCode parameter. If the FileName parameter is not specified on the command line, the iconv command reads from standard input.

You can use the System Management Interface Tool (SMIT) smit iconv fast path to run this command. The iconv command uses the LOCPATH environment variable to search for code-set converters of the form iconv/FromCodeSet_ToCodeSet. The default value of LOCPATH is /usr/lib/nls/loc.

Flags

Item Description
-c Omits characters that cannot be converted in the input file from the output. Characters that cannot be converted include characters that are invalid in the FromCode of the input or that have no corresponding character in the ToCode of the output. After omitting an unconvertible character, iconv advances to the next byte of the input to convert the next character. If -c is not used, iconv exits upon encountering a character that cannot be converted in the input. The presence or absence of -c does not affect the exit status of iconv.
-f FromCode Specifies the code set in which the input data is encoded. The space between the -f flag and the FromCode parameter is optional.
-l Writes all supported FromCode and ToCode values to standard output.
-s Suppresses any messages written to standard error concerning invalid characters. When -s is not used, an error message is written to standard error for each unconvertible or truncated character. The presence or absence of -s does not affect the exit status of iconv.
-t ToCode Specifies the code set to which the output data is to be converted. The space between the -t flag and the ToCode parameter is optional.
FileName Specifies a file to be converted.

Exit Status

This command returns the following exit values:

Item Description
0 Input data was successfully converted.
1 The specified conversions are not supported; the given input file cannot be opened for read; or there is a usage-syntax error.
2 An unusable character was encountered in the input stream.

Examples

  1. To convert the contents of the mail.x400 file from code set IBM-850 and store the results in the mail.local file, enter:
    iconv -f IBM-850 -t ISO8859-1 mail.x400 > mail.local
  2. To convert the contents of the mail.japan file from the 7-bit interchange (ISO2022) encoding to the Japanese EUC code set (IBM-eucJP), enter:
    iconv -f fold7 -t IBM-eucJP mail.japan > mail.local
  3. To convert the contents of a local file to the mail-interchange format and send mail, enter:
    iconv -f IBM-943 -t fold7 mail.local | mail fxrojas