Show special characters on Unix when using the less command

I would like to know how to view special characters when using the less command. For example, I want to see non-printable characters with special notation. For example, in the vi editor, I use set list on to see the line termination characters represented by the dollar sign $. Similarly, I would like to do this using the less command.

I called Unix less manual, but to no avail.

+64
linux unix command
Aug 04 2018-11-11T00:
source share
5 answers

less will look in its environment to see if there is a variable called LESS

You can install LESS in one of the ~ / .profile files (.bash_rc, etc. etc.), and then at any time when you run less from the comand line, it will find LESS.

Try to add this.

  export LESS="-CQaix4" 

This is the setting I use, there are some built-in behaviors that can confuse you, so ...

You can find out what all this means from the help function in less , just press the h key and nose around, or run less --help.

change

I looked for help and noticed that there is -r option

 -r -R .... --raw-control-chars --RAW-CONTROL-CHARS Output "raw" control characters. 

I agree that the cat may be the most accurate match to your stated needs.

  cat -vet file | less 

Adds '$' to the end of each line and converts the char tab to visual '^ I'.

  cat --help (edited) -e equivalent to -vE -E, --show-ends display $ at end of each line -t equivalent to -vT -T, --show-tabs display TAB characters as ^I -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB 

Hope this helps.

+61
Aug 04 '11 at 19:16
source share

You can do this with cat and this channel will be smaller:

 cat -e yourFile | less 

This excerpt from man cat explains what -e means:

  -e equivalent to -vE -E, --show-ends display $ at end of each line -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB 
+49
Aug 04 '11 at 3:15 a.m.
source share

For less use -u to display carriage returns ( ^M ) and backspaces ( ^H ) or -u to display previous and tabs ( ^I ), for example:

 $ awk 'BEGIN{print "foo\bbar\tbaz\r\n"}' | less -U foo^Hbar^Ibaz^M (END) 

Without the -u switch, the output will be:

 fobar baz (END) 

See man less for a more detailed description of functions.

+10
Aug 14 '17 at 10:15
source share

All special, non-printable characters are displayed using ^ less symbols. However, the linear feed can actually be printed (just enter a new line), so donโ€™t consider it special, so youโ€™ll have trouble replacing it. If you just want to see line endings, the easiest way might be

 sed -e 's/$/$/' | less 
0
Aug 04 '11 at 16:01
source share

In the same vein as https://stackoverflow.com/a/3189603 :

cat -A

 -A, --show-all equivalent to -vET -v, --show-nonprinting use ^ and M- notation, except for LFD and TAB -E, --show-ends display $ at end of each line -T, --show-tabs display TAB characters as ^I 

Alternatively or at the same time, you can direct tr to replace arbitrary characters with the ones you want to display before sending it to a pager, for example, less if you want.

0
Jan 15 '19 at 22:17
source share



All Articles