Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show special characters in Unix while using 'less' Command

I would like to know how to view special characters while using 'less' command. For instance I want to see the non-printable characters with a special notation. For instance in 'vi' editor I use "set list on" to see the line termination characters represented by dollar '$' character. Similarly I would want to do this using 'less' command.

I referred Unix less manual, but to no avail.

like image 696
Kingsly Avatar asked Aug 04 '11 15:08

Kingsly


People also ask

How do you handle special characters in Unix shell script?

In a shell, the most common way to escape special characters is to use a backslash before the characters. These special characters include characters like ?, +, $, !, and [. The other characters like ?, !, and $ have special meaning in the shell as well.


1 Answers

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

You can set LESS in one of your ~/.profile (.bash_rc, etc, etc) and then anytime you run less from the comand line, it will find the LESS.

Try adding this

export LESS="-CQaix4" 

This is the setup I use, there are some behaviors embedded in that may confuse you, so you can find out about what all of these mean from the help function in less, just tap the 'h' key and nose around, or run less --help.

Edit:

I looked at the help, and noticed there is also an -r option

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

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

cat -vet file | less 

Will add '$' at end of each line and convert tab char 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 

I hope this helps.

like image 94
shellter Avatar answered Sep 21 '22 21:09

shellter