2

I got this in a file:

\033[31mException log

And when I do:

less -R demo

I get no colors:

enter image description here

What am I doing wrong?

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Gabriel
  • 533
  • 1
  • 6
  • 15
  • 1
    Note that an actual escape character (U+1B) would be represented as `ESC` in inverse colors, if you ran `less demo`, without `-R`. – wjandrea Jan 20 '19 at 02:33

3 Answers3

7

You need to put the actual escape code in the file. One way to do this would be:

echo -e "\033[31mException log\033[0m" > file.txt

Then less -R file.txt should be able to interpret the color code.

user1794469
  • 3,909
  • 1
  • 23
  • 42
  • Some other ways to generate these control sequences are at https://unix.stackexchange.com/questions/491863/ . – JdeBP Jan 20 '19 at 10:31
1

These characters are not a colour code sequence, but they are the sequence to tell some tools/programming-languages to create the desired character sequence.

e.g.

echo -e "\033[31mException log"
ctrl-alt-delor
  • 27,473
  • 9
  • 58
  • 102
0

Test that your terminal actually supports the colours by running:

cat your_file.txt

If your file has colour codes, your terminal will show them. If not, then either 1) your term isn't configured to support it or 2) you've entered incorrect codes.

aggregate1166877
  • 738
  • 2
  • 10
  • 17