iconv - Convert characters from one code set to another
- iconv [-cs] [-B] [-M|-T] -f oldset -t newset [file ... file ...]
- iconv [-cs] [-B] [-M|-T] -F [-f oldset] -t newset [file ... file ...]
- iconv -l [-v]
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).
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.
You can use iconv to convert single-byte data or double-byte data.
- The byte order mark (BOM) at the beginning of the Unicode data is removed during the conversion.
- Characters containing conversion errors are not written to the output. By default,
characters not in the source character set are converted to the value
0xffand written to the output, possibly resulting in an invalid output file.
- -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 that contains an external code set.
- 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 no file tag code is 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.
- Lists supported code sets and CCSIDs. (This option was accepted in releases before V1R3, but was not supported.)
- 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 the one that is specified on the -t option.
- 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.
- Tag a new output file as text. The
txtflagwill be on and the value for code set will be the same as the one that is specified on the -t option.
- Specifies verbose output.
For information about file tagging and code set specifications, see Setting up Enhanced ASCII in z/OS UNIX System Services Planning.
- 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
- 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
- Successful completion.
- Failure due to any of the following reasons:
- Insufficient memory.
- Inability to open the input file.
- Incorrect or unknown option.
- Input contained a character sequence that is not permitted in the source code set.
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.