View previous topic :: View next topic |
Author |
Message |
v1pEr n00b
Joined: 20 Apr 2009 Posts: 63
|
Posted: Fri Jan 29, 2010 6:05 pm Post subject: How to "decolorize" output? |
|
|
I have searched high and low (but probably not high or low enough) for this but can't find a solution:
How do I remove "colored output"?
This is an example of what I mean:
Code: | [01mHP Linux Imaging and Printing System (ver. 2.8.6b)[0m
[01mSupply Levels Utility ver. 1.3[0m
[01mUsing device: hp:/usb/deskjet_5600?serial=HU3791Y0HR89[0m
[01mBlack cartridge[0m
Part No.: 56 (C6656A)
Health: Very low
[01m |
How do I remove the [01m things from my output? I want to email it with a script but this looks really messy now. I tried several things, including parsing it trough unix2dos and dos2unix but to no avail... Hope you gurus out here can help me |
|
Back to top |
|
|
NeddySeagoon Administrator
Joined: 05 Jul 2003 Posts: 54317 Location: 56N 3W
|
Posted: Fri Jan 29, 2010 6:30 pm Post subject: |
|
|
v1pEr,
Try the option --color=never on commands. Some understand it.
Also read /etc/bash/bashrc where you can set colour off for all your shells.
Its --color not --colour
Piping command output to a file drops the ANSI colour sequences too. _________________ Regards,
NeddySeagoon
Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail. |
|
Back to top |
|
|
eccerr0r Watchman
Joined: 01 Jul 2004 Posts: 9691 Location: almost Mile High in the USA
|
|
Back to top |
|
|
v1pEr n00b
Joined: 20 Apr 2009 Posts: 63
|
Posted: Fri Jan 29, 2010 7:11 pm Post subject: |
|
|
NeddySeagoon wrote: | Piping command output to a file drops the ANSI colour sequences too. | Strange, on my box it doesn't, except the following is not what you meant:
Code: | RoSe v1per # hp-levels > /tmp/hp-levels && cat -v /tmp/hp-levels
^[[01mHP Linux Imaging and Printing System (ver. 2.8.6b)^[[0m
^[[01mSupply Levels Utility ver. 1.3^[[0m |
Thank you for the thread eccerr0r! Following script works PERFECTLY!
Code: | #!/usr/bin/perl
# StripANSI .. remove ANSI codes from stdin
# Also removes removes backspace bolds and BitchX IRC ^B's
while(<>){s/\e\[[\d;]*.//g;s/(.)\cH\1/$1/g;s/\cB//g;print;} |
|
|
Back to top |
|
|
Genone Retired Dev
Joined: 14 Mar 2003 Posts: 9538 Location: beyond the rim
|
Posted: Sat Jan 30, 2010 2:14 pm Post subject: |
|
|
NeddySeagoon wrote: | Piping command output to a file drops the ANSI colour sequences too. |
That depends on the application (most programs will check if stdout is a tty and disable colors if it isn't). |
|
Back to top |
|
|
v1pEr n00b
Joined: 20 Apr 2009 Posts: 63
|
Posted: Sat Jan 30, 2010 2:17 pm Post subject: |
|
|
Genone wrote: | NeddySeagoon wrote: | Piping command output to a file drops the ANSI colour sequences too. |
That depends on the application (most programs will check if stdout is a tty and disable colors if it isn't). | And if that would have been the case, I wouldn't have needed the script in the first place |
|
Back to top |
|
|
|