iconv — Convert characters from one code set to another

Format

  • iconv [–cs] [–M|–T] –f oldset –t newset [file …file …]
  • iconv [–cs] [–M|–T] –F [-f oldset] –t newset [file …file …]
  • iconv –l [–v]

Description

iconv converts characters in file (or from standard input if no file is specified) from one code page set to another. The converted text is written to standard output (stdout). See z/OS XL C/C++ Programming Guide for more information about the code sets supported for this command.

If the input contains a character that is not valid in the source code set, iconv replaces it with the byte 0xff and continues, unless the –c option is specified.

If the input contains a character that is not valid in the destination code set, behavior depends on the system's iconv() function. See z/OS XL C/C++ Runtime Library Reference for more information about the character used for converting incorrect characters.

Also, z/OS XL C/C++ Programming Guide has a list of code pages supported by the z/OS shell.

You can use iconv to convert single-byte data or double-byte data.

Options

–c
Characters containing conversion errors are not written to the output. By default, characters not in the source character set are converted to the value 0xff and written to the output.
–f oldset
Specifies the source code set of the input. oldset can be either the code set name that is known to the system, the numeric coded character set identifier (CCSID), or a path name to a file containing an external code set.
–F
Uses the input file's coded character set (as defined in the file tag) as the source code set. If –f is also specified, and the oldset matches the file tag or if there is no file tag code set, then oldset is used as the source code set. If –F and –f are specified and oldset does not match the file tag code set, then iconv fails with an error.
–l
Lists supported code sets and CCSIDs. (This option was accepted in releases prior to V1R3, but was not supported.)
–M
Tags a new output file as mixed. The text flag (txtflag) will be off and the value for code set will be the same as what's specified on the –t option.
–s
Suppresses all error messages about faulty encodings.
–t newset
Specifies the destination code set for the output. newset can be either the code set name that is known to the system, the numeric coded character set identifier (CCSID), or a path name to a file containing an external code set.
–T
Tag a new output file as text. The txtflag will be on and the value for code set will be the same as what's specified on the –t option.
–v
Specifies verbose output.

For information about file tagging and code set specifications, see z/OS UNIX System Services Planning.

Examples

  1. To convert the file words.txt from the IBM-1047 standard code set to the ISO 8859-1 standard code set and store it in converted:
    iconv –f IBM-1047 –t ISO8859-1 words.txt > converted

    Also, for the exact conversion table names, refer to z/OS XL C/C++ Programming Guide.

  2. To convert the file mbcsdata, which is in code page IBM-932 (double-byte ASCII), to code page IBM-939 and put the output in a file called dbcsdata:
    iconv –f IBM-932 –t IBM-939 mbcsdata > dbcsdata

Localization

iconv uses the following localization environment variables:
  • LANG
  • LC_ALL
  • LC_CTYPE
  • LC_MESSAGES
  • NLSPATH

See Localization for more information.

Exit values

0
Successful completion
1
Failure due to any of the following:
  • Insufficient memory
  • Inability to open the input file
  • Incorrect or unknown option
2
Input contained a character sequence that is not permitted in the source code set

Portability

X/Open Portability Guide.

–v is an extension to the POSIX.2 standard. The –c, –l, and –s options are extensions to the XPG standard.