Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How to "decolorize" output?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
v1pEr
n00b
n00b


Joined: 20 Apr 2009
Posts: 63

PostPosted: Fri Jan 29, 2010 6:05 pm    Post subject: How to "decolorize" output? Reply with quote

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:
HP Linux Imaging and Printing System (ver. 2.8.6b)
Supply Levels Utility ver. 1.3

Using device: hp:/usb/deskjet_5600?serial=HU3791Y0HR89

Black cartridge
Part No.: 56 (C6656A)
Health: Very low



How do I remove the  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
View user's profile Send private message
NeddySeagoon
Administrator
Administrator


Joined: 05 Jul 2003
Posts: 54317
Location: 56N 3W

PostPosted: Fri Jan 29, 2010 6:30 pm    Post subject: Reply with quote

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
View user's profile Send private message
eccerr0r
Watchman
Watchman


Joined: 01 Jul 2004
Posts: 9691
Location: almost Mile High in the USA

PostPosted: Fri Jan 29, 2010 6:32 pm    Post subject: Reply with quote

I wrote a pipe filter that removes ANSI code sequences some people felt useful... have it in this post.

https://forums.gentoo.org/viewtopic-t-804211-highlight-stripansi.html
_________________
Intel Core i7 2700K/Radeon R7 250/24GB DDR3/256GB SSD
What am I supposed watching?
Back to top
View user's profile Send private message
v1pEr
n00b
n00b


Joined: 20 Apr 2009
Posts: 63

PostPosted: Fri Jan 29, 2010 7:11 pm    Post subject: Reply with quote

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
View user's profile Send private message
Genone
Retired Dev
Retired Dev


Joined: 14 Mar 2003
Posts: 9538
Location: beyond the rim

PostPosted: Sat Jan 30, 2010 2:14 pm    Post subject: Reply with quote

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
View user's profile Send private message
v1pEr
n00b
n00b


Joined: 20 Apr 2009
Posts: 63

PostPosted: Sat Jan 30, 2010 2:17 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum