1
LC_ALL=ru_RU.CP1251 less ~/t/show_discounts.js

shows nonsense characters instead of showing this CP1251 file as it should be viewed.

How to make less work well with specified encoding?

Debian Linux, Gnome Terminal with the system configured as as en_US.UTF-8.

6

Running less as

LC_ALL=ru_RU.CP1251 less file

provided that ru_RU.CP1251 locale exists on your system (see if LC_ALL=ru_RU.CP1251 locale charmap returns CP1252) tells less that you are in that locale, which means that the file is encoded in that charset and that the terminal uses that charset.

If the terminal emulator was started in a locale where the charset is UTF-8, it will expect characters coded in UTF-8 so won't know what to do with those CP1251 encoded characters that less is throwing at it.

You'd need to also start the terminal emulator in that locale, or you could use luit to do the translation (provided the terminal's charset is UTF-8).

Or you could use iconv to convert the file into the terminal's locale charset:

iconv -f CP1251 < file | less

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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