Sometimes the commands’ output have some non-printable ASCII characters. How to filter away these non-printable ASCII characters on Linux?
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 '11121540-176' > output.txt