Convert encoding of a file from one character set encoding to another.
Syntax
iconv [Option...] -f fromCode -t toCode inputfile...
iconv -l
Options
-f encoding
--from-code=encoding
Convert characters From encoding.
-t encoding
--to-code=encoding
Convert characters To encoding.
-l
--list
List the names of the supported encodings
For the libiconv implementation, the names are printed in upper case, separated by
whitespace, and alias names of an encoding are listed on the same line as the encoding itself.
Options controlling conversion problems:
-c When this option is given, characters that cannot be converted are silently
discarded, instead of leading to a conversion error.
--unicode-subst=formatstring
Replace Unicode characters that cannot be represented in the target
encoding with a placeholder string that is constructed from formatstring,
applied to the Unicode code point. The formatstring must be in the same
format as for the printf command or the printf() function, taking either
no argument or exactly one unsigned integer argument.
--byte-subst=formatstring
Replace bytes in the input that are not valid in the source encoding
with a placeholder string constructed from the given formatstring,
applied to the byte's value. The formatstring must be in the same
format as for the printf command or the printf() function, taking either
no argument or exactly one unsigned integer argument.
--widechar-subst=formatstring
Replace wide characters in the input that are not valid in the source
encoding with a placeholder string that is constructed from the given
formatstring, applied to the byte's value. The formatstring must
be in the same format as for the printf command or the printf() function,
taking either no argument or exactly one unsigned integer argument.
Options controlling error output:
−s
−−silent
Suppress error messages about invalid or unconvertible characters are omitted.
The iconv program converts the encoding of characters in inputfile from one coded character set to another. The result is written to standard output unless otherwise specified by the --output option.
Examples
Convert input.txt from ISO-8859-1 to UTF-8 and save as output.txt
$ iconv -f ISO-8859-1 -t UTF-8 < input.txt > output.txt
Convert Demo1.txt and Demo2.txt from WINDOWS-1252 to UTF-8 and save as a single file output.txt
$ iconv -f WINDOWS-1252 -t UTF-8 Demo1.txt Demo2.txt > output.txt
“Acceptance of a double standard has always been a sign of inferiority. To let someone behave according to one set of principles or values while demanding that you be subjected to others is to validate a claim of superiority that justifies the inconsistent and unfair behavior” - Bruce Thornton (The Truth about Tolerance)
Related macOS commands:
uuencode - Encode a binary file
Character encoding - Wikipedia
Equivalent (Linux) bash command: iconv - Convert encoding of a file from one character set encoding to another.