0
mbp:Desktop alexus$ file $$.txt
235.txt: ISO-8859 text, with CRLF line terminators
mbp:Desktop alexus$ 

Yet this isn't really ISO-8859 but 8859-5 (Russian).

The file opens up on Windows just fine (I can see Russian characters) and on a Mac I get either some unknown symbols or question marks.

Is there a solution?

2 Answers 2

2

To open the file without converting its encoding, you will need find a way to specify the file’s encoding to whatever program is opening it.

You will want to avoid double-clicking on the file and instead directly use the Open… menu item (usually ⌘O or Open… under the File menu) of the application you want to use to view/edit the file. If the application is capable of reading files in other encodings, it will probably let you specify the encoding in the Open… dialog (similarly, they should let you specify a (possibly different) encoding when using Save As…).

For example, TextEdit has drop down list for “Plain Text Encoding” at the bottom of the Open… dialog. If ISO 8859-5 is not listed you may need to select “Customize Encodings List…” to add it to the list. You may want “Cyrillic (ISO 8859-5)”, “Cyrillic (Windows)”, “Cyrillic (KOI8-R)”, or something else (use 8859-5 if you are sure that is the encoding, otherwise I am not sure if the code point assignments of the other Cyrillic encodings are at all similar).

Terminal normally expects UTF-8 encoded characters, so you should transcode the data to UTF-8 if you just want to “cat” the file.

iconv -f ISO-8859-5 -t UTF-8 < filename

You can also use iconv to save a copy of the converted file (you may find it easier to work with a UTF-8 file since many programs will default to decoding a file as UTF-8):

iconv -f ISO-8859-5 -t UTF-8 < filename > filename.utf8.txt

You can get a full list of the encodings that iconv supports with iconv -l.

If you want to use a program to view/edit the file inside Terminal, then the steps (again) depend on the program you are using. You might do it in Vim like this:

vim -c 'e ++enc=iso-8859-5 filename'

Or if Vim is already started:

:e ++enc=iso-8859-5 filename

You can get a list of the encodings that Vim knows with :help *encoding-names*.

0

Use iconv to convert the file to UTF-8.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .