Character Encoding: Convert from UTF-8 to ISO-8859-1

The iconv program converts the encoding of characters in an input file from one coded character set to another. The commands here have been tested on RHEL 5 but it should work on other Linux distributions just fine,

I already have a test UTF-8 encoded file,

# file -bi TestspecialchrUTF.txt
text/plain; charset=utf-8

Let's convert this file,

# iconv --from-code=utf-8 --to-code=iso-8859-1//TRANSLIT TestspecialchrUTF.txt -o TestISO8859.txt

Here the catch is TRANSLIT switch which is not present in man page of iconv at the time of writing this blog post. Now let's verify the character encoding of newly created file,

# file -bi TestISO8859.txt
text/plain; charset=iso-8859-1

Where, file is a unix command to determine the file type.

Any feedback will be highly appreciated.

Suggested Posts,

This post appeared on the by Sumit Goel. Copyright © 2012 – and Sumit Goel. All rights reserved. Not to be reproduced for commercial purposes without written permission.

1 comment:

  1. Can I ask a question?

    I am converting UTF-8 to ISO-8859-1 file using the following command
    iconv -f UTF-8 -t ISO-8859-1//TRANSLIT input.txt > out.txt
    After conversion, when I open the out.txt
    ¿Quién Gómez is translated to ¿Quien Gomez.

    Why is é and ó and others are not translated correctly?

    Thank you.


Be sure to check back again because I do make every effort to reply to your comments here.