Is there a tool to robustly render a text with escape sequences (eg a terminal log) ?
This question is related to render text with escape squence (like a terminal) (My edits to that question were rejected so I'm posting a new one here with a concrete new use case; the answers to the above question fail to address this use case).
For example, I'd like to search for a string in a terminal log and only search for strings actually displayed, eg:
$script terminal_log.txt
logging to terminal_log.txt
$echo bar<BACKSPACE><BACKSPACE><BACKSPACE>foo
foo
$cat terminal_log.txt|grep -c bar
1
$cat terminal_log.txt|sometool|grep -c bar
0
sometool would render the text by completely removing bar (which was deleted by user with 3 backspaces) exactly as shown in the terminal output, whereas cat doesn't remove it.
[edit] here is another example that shows the proposed col -b
doesn't work:
$echo bar
bar
$clear
#the screen is cleared
$cat terminal_log.txt
#nothing shown, in particular no bar
$cat terminal_log.txt|col -b|grep -c bar
2
We get 2 instead of 0 even though cat terminal_log.txt
doesn't show bar
(it's hidden due to the terminal sequences).
So the utility col -b
doesn't handle terminal commands such as clear etc.
What I'm looking for is a utility that would render exactly what is displayed on the terminal.