Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.
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?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

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*.

share|improve this answer

Use iconv to convert the file to UTF-8.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.