Code Snippets & Stripping ANSI Escape Sequences

For discussions about programming and projects not necessarily associated with Porteus.
Bogomips
Full of knowledge
Full of knowledge
Posts: 2564
Joined: 25 Jun 2014, 15:21
Distribution: 3.2.2 Cinnamon & KDE5
Location: London

Code Snippets & Stripping ANSI Escape Sequences

Post#1 by Bogomips » 09 May 2015, 16:29

Got solution for Stripping ANSI Escape Sequences from http://www.commandlinefu.com/commands/v ... 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
Last edited by Bogomips on 21 Dec 2015, 13:20, edited 1 time in total.
Reason: Informative Link
Linux porteus 4.4.0-porteus #3 SMP PREEMPT Sat Jan 23 07:01:55 UTC 2016 i686 AMD Sempron(tm) 140 Processor AuthenticAMD GNU/Linux
NVIDIA Corporation C61 [GeForce 6150SE nForce 430] (rev a2) MemTotal: 901760 kB MemFree: 66752 kB