How to display nonprintable characters in a text file

By Alvin J. Alexander, devdaily.com

I just ran into a need to see what non-printable characters were embedded in a text file in a Unix system, and remembered this old command:

sed -n 'l' myfile.txt

Note that the character above is a lower-case letter "L", and not the number one ("1").

This command shows the contents of your file, but displays nonprintable characters with the octal values. On some systems tab characters may also be shown as ">" characters. This is similar to using the cat command, except for the handling of the non-printing characters.


devdaily logo