
10-03-2007, 10:58 PM
|
| Junior Member | | Join Date: Sep 2009
Posts: 0
| |
Re: tail with color? * Andreas Karrer wrote:
> * Troy Piggins :
>> I'm using 'tail -f /var/log/mail.log' to keep an eye on my mail
>> logs while testing. I was wondering if there is any tools
>> similar that might have the ability to color keywords (maybe
>> based on REs)? This would help certain keywords stand out more.
>>
>> Or can the output be piped through another application that may
>> be able to do it?
>
> tail -f file | perl -pe 's/keyword/\e[1;31;43m$&\e[0m/g'
>
> This only works on ANSI terminals, but all others have become virtually
> extinct. \e[...m ist the ANSI escape sequence SGR "select graphic
> rendition". The "..." can be replaced by some semicolon-separated
> integers, with the meaning:
>
> 0 : all attributes off
> 1 : bold
> 31 : foreground red
> 43 : background yellow
>
> "keyword", of course, can be any perl regular expression:
>
> (foo|bar) highlight the strings foo and bar
> \b((foo|bar)\b highlight the words foo and bar
> .*\b((foo|bar)\b.* highlight the whole line that contains the words foo or bar
Wow - that's awesome! Thanks Andreas!
--
Troy Piggins
,-o
o ) Ubuntu linux 6.06 http://ubuntu.com RLU#415538 http://counter.li.org
`-o uptime: 16:39:26 up 18 days,22:08,2 users,load average:0.00,0.00,0.00 |