5

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.

John Garreth
  • 1,112
  • 2
  • 10
  • 17
  • 3
    well cat has many options to show non printable characters, so `cat -vET` should show you what you want. Redirect your output to `cat` and see what happens – abasu May 22 '13 at 13:28
  • 1
    it seems that cat does not distinguish between `\r\n` and `\n`,... – John Garreth May 22 '13 at 14:38

1 Answers1

6

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
Community
  • 1
  • 1
Jakub M.
  • 32,471
  • 48
  • 110
  • 179
  • Nice one! Unfortunately this does not highlight line breaks. I tried: `head -n100 large.file | perl -pe 's/(\n+)/\033[41m$1\033[00m/g'`. – John Garreth May 22 '13 at 14:40
  • I used the solution by abasu. Anyway, yours is colourful, and abasu only wrote a comment. Maybe one could also try search and replace `\n -> \\n\n`. This would show everything, and could also hightlight `\r`. – John Garreth May 25 '13 at 13:10