Monday, April 7, 2008

Mac OS X Text file encoding conversion

In Mac OS X is builtin utility for converting text files from one to another encoding. This can be useful when the need to convert files from the national character sets to UTF-8.

Go to console and type: iconv -l
This will show list of supported encodings

For converting file "index.html" in current directory from russian code page CP1251 into UTF-8 type:

iconv -f CP1251 -t UTF-8 index.html > index-utf-8.html

or desc order if index.html in utf-8 format:

iconv -f UTF-8 -t CP1251 index.html > index-cp1251.html

5 comments:

Anonymous said...

How to tell a file’s encoding?

ferretti75 said...

how about changing the filesystem's default enoding ? it uses a "mac-roman" which is a hassle if you're programming or writng config files that need to be copied over different platforms

Anonymous said...

Thanks, nice tip! Easier than trying to convert huge textfiles with a GUI app.

To tell a files encoding try "file " in terminal.

Firoz Khan said...

Video Converter for MacTotal Video Converter for Mac is All-in-one Video Converter for Mac to convert and burn all videos, avi to mp4, iPad, iPhone, DVD. It’s best Mac Video Converter

Firoz Khan said...

Video Converter for MacTotal Video Converter for Mac is All-in-one Video Converter for Mac to convert and burn all videos, avi to mp4, iPad, iPhone, DVD. It’s best Mac Video Converter