How to translate and remove non-printable characters?

175 Views Asked by At

I know there are a lot of ways to remove non-printable characters in Linux like sed or tr. But I want to remove them as cat command print. Here comes my example file which comes from telnet:

ae23        Enabled     Down    Disabled      Auto    Auto                                                    ^M^@^M
ae24        Enabled     Down    Disabled      Auto    Auto                                                    ^M^@^M
^[[J^M^@ --More-- (END) ^[[J^M^@ --More-- (END) ^[[J^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^[[J^[[J^[[J^M^@test-40.Int> exit

There are some extra characters including non-printable and printable like ^[, ^H, ^M, [J, --More-- (END) and so on. When I use cat to print the file, the result shows:

ae23        Enabled     Down    Disabled      Auto    Auto
ae24        Enabled     Down    Disabled      Auto    Auto
test.Int> exit

That's what I want. However, only use sed and tr can only remove the non-printable characters except [J, --More-- (END).
So how to remove all of them just like the cat show? In my point of view, it's a "translation" way but not "remove" way.

0

There are 0 best solutions below