WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Filter color codes from school scripts.  (Read 1409 times)

Offline Greg Erskine

  • Sr. Member
  • ****
  • Posts: 404
Filter color codes from school scripts.
« on: May 17, 2023, 04:21:04 PM »
* filetool.sh: having colors from alphons

Say you have developed an application that calls the standard TCL scripts and you don't want the colour escape sequences, what do you do?

For example, calling TCL scripts from html cgi.

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11282
Re: Filter color codes from school scripts.
« Reply #1 on: May 17, 2023, 06:10:09 PM »
Hi Greg Erskine
Maybe pipe the output through  sed:
Code: [Select]
sed -e 's/\x1b\[[0-9;]*m//g'Found here:
https://superuser.com/a/380778

Result of echoing color code through  sed  command:
tc@E310:~$ echo -e "color \033[1;31mRED\033[0m output"
color RED output
tc@E310:~$ echo -e "color \033[1;31mRED\033[0m output" | sed -e 's/\x1b\[[0-9;]*m//g'
color RED output


Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11282
Re: Filter color codes from school scripts.
« Reply #2 on: May 17, 2023, 06:43:56 PM »
Hi Greg Erskine
I just did some more testing and it does not work with  busybox sed.
You need  sed.tcz.

Offline Greg Erskine

  • Sr. Member
  • ****
  • Posts: 404
Re: Filter color codes from school scripts.
« Reply #3 on: May 17, 2023, 07:21:00 PM »
Thanks Rich

I'm pretty sure I have done it before somewhere. I'll look into it further.

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1095
Re: Filter color codes from school scripts.
« Reply #4 on: May 17, 2023, 07:28:53 PM »
Code: [Select]
sed "s///g" | sed "s/\x0d//g" | sed -r "s/\[([0-9]{1,2}(;[0-9]{1,2}?)?)?[m|K]//g"'

The first sed command didn’t paste properly

Edit.  Found it in my commit message for one of my scripts.

busybox sed does not undertstan \x1b control code, but does understand when <ctrl>-v <ESC>
   is used to insert ^[
   \x0d works just fine for for ^M escape code.

« Last Edit: May 17, 2023, 07:32:32 PM by Paul_123 »

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1095
Re: Filter color codes from school scripts.
« Reply #5 on: May 17, 2023, 07:46:38 PM »
I should add that using control codes doesn’t work with all editors.   vi does work fine.