0

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.

vinllen
  • 1,369
  • 2
  • 18
  • 36
  • Why are you using `more` in the first place? Just `unset PAGER` in the environment where you are getting these results, or don't pipe to `more` if you are explicitly doing that. – tripleee Dec 12 '17 at 11:50
  • `colcrt` can remove (some) formatting codes similarly to using `cat` on a file with screen control codes. – tripleee Dec 12 '17 at 11:52
  • @tripleee `more` is needed, showing the result on one page in not what I want. `cat` is a command can show without non-printable characters. But I want to remove all the extra characters just as the question shows and then pass the remaining string to the next pipeline step. – vinllen Dec 12 '17 at 11:58
  • No, `cat` displays all the characters in the file completely verbatim, but your terminal interprets them (switching to boldface, backspacing over text, etc) so when it finishes you see what looks like text without terminal control codes. – tripleee Dec 12 '17 at 11:59
  • How is `more` needed if you eventually intend to pass this to a pipe? Capture the output and pipe it to `more` separately in an interactive session if that's what you want. – tripleee Dec 12 '17 at 12:01
  • @tripleee it's a user interactive way just like the `telnet` command. The user just wants to display one page at a time. – vinllen Dec 12 '17 at 12:03
  • @tripleee The question you mentioned https://unix.stackexchange.com/questions/14684/removing-control-chars-including-console-codes-colours-from-script-output works for me. All the `more` characters are removed! – vinllen Dec 12 '17 at 12:10
  • @tripleee Yes, my fault. This question can be marked duplicate. – vinllen Dec 12 '17 at 12:13

0 Answers0