Show special characters in Unix while using 'less' Command
You can do that with cat and that pipe the output to less:
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
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.
In the same spirit as https://stackoverflow.com/a/6943976/7154924:
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 pipe to tr
to substitute arbitrary characters to the desired ones for display, before piping to a pager like less
if desired.
For less
use -u
to display carriage returns (^M
) and backspaces (^H
), or -U
to show the 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 would be:
fobar baz
(END)
See man less
for more exact description of the features.