
10-03-2007, 10:58 PM
|
| Junior Member | | Join Date: Sep 2009
Posts: 0
| |
Re: tail with color? * 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
- Andi |