Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Colorize text matching a regex through a pipe?



On 01/18/2011 02:08 PM, Daniel Hedlund wrote:
> On Wed, Dec 29, 2010 at 08:52, David Kramer <david-8uUts6sDVDvs2Lz0fTdYFQ at public.gmane.org> wrote:
>> Is there a linux tool that can work as a pipe (read stdin, write to stdout) and colorize any text
>> matching an regex?  If not, I'll have to write one.  Not that hard, but I would hate to reinvent
>> it.
> 
> egrep (grep -E) does this, at least the version I'm using does:
> 
> cat /etc/services | egrep --color=auto '#.+$'
> cat /etc/services | egrep --color=always ''#.+$'' | less -R
> 
> # change match color to bright green
> export GREP_COLOR='1;32'
> cat /etc/services | egrep --color=always ''#.+$'' | less -R
> 
> 
> I usually alias less="less -R" in my bashrc so I don't have to
> remember to add that every time.

Thanks.  I played with this, and with colortail.  I didn't really like
either solution in the end.  [e]grep only allows one color and one
pattern, and colortail doesn't actually work as a filter (the author
"has a patch for that").

I ended up going with a perl script I wrote, which lets me have
different patterns output with different colors, and our developers
already have perl, not colortail,





BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org