Filter away non-printable ASCII characters on Linux?

Sometimes the commands' output have some non-printable ASCII characters. How to filter away these non-printable ASCII characters on Linux?

asked Jun 14, 2014 by Eric Z Ma (44,280 points)

1 Answer

 
Best answer

You can consider the problem as "how to leave only printable ascii characters?".

The printable characters in ASCII table are:

Octal 011: Tab
Octal 012: Line Feed
Octal 015: Carriage Return
Octal 040 to 176: printable codes

Then, you can use tr to get only these characters:

cat input.txt | tr -cd '\11\12\15\40-\176' > output.txt
answered Jun 18, 2014 by Eric Z Ma (44,280 points)

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...