Unix: Converting Files from One Encoding to Another (on Linux and FreeBSD)

Practice



Task: convert files from one encoding (for example, KOI8-R) to another (for example, UTF-8). This needs to be done from Unix (i.e., FreeBSD, Linux Debian, CentOS, Ubuntu, RedHat).


For this we use the iconv utility.

1) Installing

On Debian/Ubuntu and CentOS/RedHat this utility comes out of the box — it isn't even listed in the repositories.

On FreeBSD it's also installed by default, but if it happens to be missing:

$ cd /usr/ports/converters/iconv
$ sudo make install clean


2) Using it

The usage is very simple. Here's an example:

$ iconv -f KOI8-R -t UTF8 myfile1.txt > myfile2.txt

here the parameters are:
  • -f : source encoding (to convert from)
  • -t : target encoding (to convert to)
  • myfile1.txt : source file
  • myfile2.txt : target file

As you can see, it's all simple.

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "LINUX operating system"

Terms: LINUX operating system