convert encoding with iconv

August 24th, 2007
Most Unix-like systems are equipped with a powerful program called iconv. This program enables you to convert any file from virtually any encoding to another. The syntax of the command is as follows:

iconv -f from-encoding -t to-encoding input-file

For example, this command

iconv -f WINDOWS-1253 -t UTF-8 input.txt

will convert the contents of the input.txt file from windows-1253 encoding to utf-8. The output will be sent to standard output. If you want to write the converted output to a file you should use redirection:

iconv -f WINDOWS-1253 -t UTF-8 input.txt > output.txt

If the input-file parameter is omitted, standard input will be used.

To get a list with all the encodings supported in your system by iconv, run this command:

iconv -l

If you are interested in iconv but you are a Windows user, the good news is that iconv is included in GnuWin32.

Leave a Reply