1

If I use cat on a file containing UTF-8, it displays properly:

% cat /tmp/sample
<concept code="endangeredLanguage">
  <description value="The language is endangered at the given date"@en/>
  <description value="La lengua está en vías de extinción en la fecha dada"@es/>
  <description value="O idioma está em vias de extinção na data indicada"@pt/>
  <description value="La langue est menacée à la date indiquée"@fr/>
  <description value="ある時点でその言語は絶滅寸前である"@ja/>
  <description value="De taal is bedreigd met uitsterven op de gegeven datum"@nl/>
</concept>

But if I use "less", the non-ASCII characters are escaped:

% less /tmp/sample
<concept code="endangeredLanguage">
  <description value="The language is endangered at the given date"@en/>
  <description value="La lengua est<C3><A1> en v<C3><AD>as de extinci<C3><B3>n en la fecha dada"@es/>
  <description value="O idioma est<C3><A1> em vias de extin<C3><A7><C3><A3>o na data indicada"@pt/>
  <description value="La langue est menac<C3><A9>e <C3><A0> la date indiqu<C3><A9>e"@fr/>
  <description value="<E3><81><82><E3><82><8B><E6><99><82><E7><82><B9><E3><81><A7><E3><81><9D><E3><81><AE><E8><A8><80><E8><AA><9E><E3><81><AF><E7><B5><B6><E6><BB><85><E5><AF><B8><E5><89><8D><E3><81><A7><E3><81><82><E3><82><8B>"@ja/>
  <description value="De taal is bedreigd met uitsterven op de gegeven datum"@nl/>
</concept>

presumably because less is treated them as though they were binary. How can I paginate the output, but still see the proper characters?

  • 1
    What does env LANG=en_US.UTF-8 less /tmp/sample show? – thrig Feb 17 '16 at 23:11
  • I second @thrig - with UTF-8 locale set, my less shows the correct Unicode characters. (less 481 (PCRE regular expressions)) – muru Feb 18 '16 at 1:52
2

It is explained in the less FAQ Can less display non-English language characters?

Less has two ways to display non-English characters. If your system uses a non-ASCII single-byte character set, you should set up your system with the correct "locale" settings. If your system does not support setlocale, you can set the LESSCHARSET or LESSCHARDEF environment variable to tell less what language you are using. See the section "NATIONAL CHARACTER SETS" in the man page for details.

If your system supports the UTF-8 encoding of Unicode for non-ASCII text, as many modern systems do, you should either set your locale to something that includes the "UTF-8" or "UTF8" (either uppercase or lowercase is ok), or set LESSCHARSET to "utf-8".

2

Add the following variable to your environment:

export LESSCHARSET=utf-8

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.