We want to remove ^[
, and all of the escape sequences.
sed is not working and is giving us this error:
$ sed 's/^[//g' oldfile > newfile; mv newfile oldfile;
sed: -e expression #1, char 7: unterminated `s' command
$ sed -i '' -e 's/^[//g' somefile
sed: -e expression #1, char 7: unterminated `s' command
I built vtclean for this. It strips escape sequences using these regular expressions in order (explained in regex.txt):
It additionally does basic line-edit emulation, so backspace and other movement characters (like left arrow key) are parsed.
ansi2txt command (part of kbtin package) seems to be doing the job perfectly on Ubuntu.
I managed with the following for my purposes, but this doesn't include all possible ANSI escapes:
This removes
m
commands, but for all escapes (as commented by @lethalman) use:Also see "Python regex to match VT100 escape sequences".
There is also a table of common escape sequences.