How to make whitespaces visible in the command lin

2019-03-30 08:58发布

问题:

I have a very large file, of which I want to inspect the first 100 lines using head:

head -n100 large.file

I'd really like to make whitespaces lik \t \r,... visible. How can I do this. I did not find an option in man head.

回答1:

You can do it with Perl

echo 'fooo        bar' | perl -pe 's/( +)/\033[41m$1\033[00m/g'

\033[41m enables red color and \033[00m disables it. Perl with -pe works like sed and is needed only to put those special sequences around spaces.

To highlight line breaks change the first part of the regular expression to

s/([ \n]+)/...rest of the expression