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.

I have to sort some lines of cyrillic characters and I want to use the sort utility (on MAC OS X 10.6). The problem is that result is incorrect. I take the text into clipboard, then run pbpaste | sort This is plaintext data, and I also tried passing a file to the sort command.

My source data is

Биатлон
Арбуз
Фото
Пума
Перина
Новость
Карандаш
Перина с двумя пододеяльниками
Карикатура
Куст
Фигура

And after sorting I get

Куст
Пума
Фото
Арбуз
Перина
Фигура
Перина с двумя пододеяльниками
Биатлон
Новость
Карандаш
Карикатура

Theese lines aren’t even grouped by first letter. I tried option -d, but then I get an error

sort: string comparison failed: Illegal byte sequence sort: Set LC_ALL='C' to work around the problem. sort: The strings compared were \320\321\321\321' and\320\320\320\321\321\320’.

Exporting the variable as recommended doesn’t solve the problem. What can I do to use the sort utility for such a task? Any additional info is necessary?

share|improve this question

2 Answers 2

Try to save the data in unicode encoded (or UTF8) file, and if sort utility is unicode enabled, it should work. I guess, the problem is that pbpaste does not set the encoding properly. I'm not Mac user, so its just a guess.

share|improve this answer
    
I've also tried with UTF-8 file, but since the result was the same I didn’t mention it. –  Anton Mar 16 '10 at 17:44

I believe you need to set the locale. I think you can do this:

LC_ALL="ru" pbpaste | sort

(The first part sets the LC_ALL environment variable for the duration of the command.)

I'm running Leopard. When I issue a pbpaste, all characters are substituted for question marks. I did save the text to a UTF-8-encoded file called sort_temp.txt, and running:

sort sort_temp.txt 

gives the same improperly sorted list that you posted, but running

LC_ALL="ru" sort sort_temp.txt

or

LANG="ru" sort sort_temp.txt

gives a properly sorted list.

share|improve this answer
    
Thanks, it helps! –  Anton Mar 16 '10 at 17:43

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.