Page 1 of 1

Code Snippets & Stripping ANSI Escape Sequences

Posted: 09 May 2015, 16:29
by Bogomips
Got solution for Stripping ANSI Escape Sequences from ... ed#comment , on an interesting site facilitating saving and sharing code snippets in the Cloud.

Solution chosen was sed "s,\x1B\[[0-9;]*[a-zA-Z],,g". This did not however do a complete job in the case of:

Code: Select all

root@porteus:/home/guest# usm -g babl 2>&1 | tee -a ue
guest@porteus:~$ less ue
which was spattered with escape sequences, all of which were removed except for 'ESC(B' at end of line.

Another sed line had to be added to complete the solution for this particular file:

Code: Select all

guest@porteus:~$ sed "s,\x1B\[[0-9;]*[a-zA-Z],,g
> s/\x1b(B$//" ue > ut
guest@porteus:~$ less ut
Info: ANSI Escape Sequences in Shell Scripts