Saturday, July 07, 2007

Converting file encoding in Linux

If you usually use both Windows and Linux, you might have experienced the disappointing fact that files created on Linux don't show properly in Windows and vice versa. This is caused by the different file encodings that each operating system usually work with.

You can overcome this problem in Windows using a software called notepad++, an open software powerful replacement for the tiny notepad. This software lets you change the encoding of a file, and automatically detects the actual encoding of the file you are opening.

In linux things are usually more complicated yet more powerful. There is a command that you have to execute in a system console that lets you convert file encoding:

> iconv -f [in encoding] -t [out encoding] [in filename]

This command do not write a new file, instead it writes the converted characters to the console, so in order to create a new file with the desired encoding you have to redirect the output:


> iconv -f [in encoding] -t [out encoding] [in filename] > [out filename]

Here you are an actual example:

> iconv -f iso88591 -t utf8 in.tex > out.tex

This will convert the file in.tex from iso88591 encoding to utf8, a more suitable encoding for Linux.

I hope this has been useful for you.

0 Comentarios:

Post a Comment

<< Home