General TC > Programming & Scripting - Unofficial

Filter color codes from school scripts.

(1/2) > >>

Greg Erskine:
* 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.

Rich:
Hi Greg Erskine
Maybe pipe the output through  sed:

--- Code: ---sed -e 's/\x1b\[[0-9;]*m//g'
--- End code ---
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

Rich:
Hi Greg Erskine
I just did some more testing and it does not work with  busybox sed.
You need  sed.tcz.

Greg Erskine:
Thanks Rich

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

Paul_123:

--- Code: ---sed "s///g" | sed "s/\x0d//g" | sed -r "s/\[([0-9]{1,2}(;[0-9]{1,2}?)?)?[m|K]//g"'

--- End code ---

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.

Navigation

[0] Message Index

[#] Next page

Go to full version