Code Snippets & Stripping ANSI Escape Sequences

For discussions about programming and projects not necessarily associated with Porteus.

Code Snippets & Stripping ANSI Escape Sequences

Postby Bogomips » 09 May 2015, 17:29

Got solution for Stripping ANSI Escape Sequences from , 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, 14: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
Full of knowledge
Full of knowledge
Posts: 2435
Joined: 25 Jun 2014, 16:21
Location: London
Distribution: 3.2.2 Cinnamon & KDE5

Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest