fixunix
Tags Register FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

tail with color? - Unix

This is a discussion on tail with color? - Unix ; 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 ...


Fix Unix > Unix > tail with color?

Reply
 
LinkBack Tools
  #1  
Old 10-03-2007, 10:58 PM
Junior Member
 
Join Date: Sep 2009
Posts: 0
Default tail with color?

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?

--
Troy Piggins
,-o
o ) Ubuntu linux 6.06 http://ubuntu.com RLU#415538 http://counter.li.org
`-o uptime: 12:17:59 up 18 days,17:46,2 users,load average:0.00,0.00,0.00
Reply With Quote
  #2  
Old 10-03-2007, 10:58 PM
Junior Member
 
Join Date: Sep 2009
Posts: 0
Default 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
Reply With Quote
  #3  
Old 10-03-2007, 10:58 PM
Junior Member
 
Join Date: Sep 2009
Posts: 0
Default 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
Reply With Quote
  #4  
Old 10-03-2007, 10:58 PM
Junior Member
 
Join Date: Sep 2009
Posts: 0
Default Re: tail with color?

Troy Piggins wrote:
> 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.


Type "less /var/log/mail.log". Then type "/foo", where "foo" is
a regular expression matching whatever you want to highlight, and
hit return. Now type "F".

- Logan
Reply With Quote
  #5  
Old 10-03-2007, 10:58 PM
Junior Member
 
Join Date: Sep 2009
Posts: 0
Default Re: tail with color?

* Logan Shaw wrote:
> Troy Piggins wrote:
>> 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.

>
> Type "less /var/log/mail.log". Then type "/foo", where "foo" is
> a regular expression matching whatever you want to highlight, and
> hit return. Now type "F".


Thanks Logan, I didn't know less could 'follow'.

The other solution by Andreas I like because I can run through a
script and use 256 colors for all sort of regexes.

--
Troy Piggins
,-o
o ) Ubuntu linux 6.06 http://ubuntu.com RLU#415538 http://counter.li.org
`-o uptime: 19:57:53 up 20 days,1:26,2 users,load average:0.04,0.03,0.00
Reply With Quote
  #6  
Old 10-03-2007, 10:58 PM
Junior Member
 
Join Date: Sep 2009
Posts: 0
Default Re: tail with color?

The carbonbased lifeform Troy Piggins inspired comp.unix.admin with:
> * Logan Shaw wrote:
>> Troy Piggins wrote:
>>> 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.

>>
>> Type "less /var/log/mail.log". Then type "/foo", where "foo" is
>> a regular expression matching whatever you want to highlight, and
>> hit return. Now type "F".

>
> Thanks Logan, I didn't know less could 'follow'.
>
> The other solution by Andreas I like because I can run through a
> script and use 256 colors for all sort of regexes.


Or use e.g. http://www.vanheusden.com/multitail/ , or
http://lofimo.anzac.at/ or another log-analyser

Theo
--
theo at van-werkhoven.nl ICQ:277217131 SuSE Linux
linuxcounter.org: 99872 Jabber:muadib at jabber.xs4all.nl AMD XP3000+ 1024MB
"ik _heb_ niets tegen Microsoft, ik heb iets tegen
de uitwassen *van* Microsoft"
Reply With Quote
  #7  
Old 10-03-2007, 10:58 PM
Junior Member
 
Join Date: Sep 2009
Posts: 0
Default Re: tail with color?

* Theo v. Werkhoven wrote:
> The carbonbased lifeform Troy Piggins inspired comp.unix.admin with:
>> * Logan Shaw wrote:
>>> Troy Piggins wrote:
>>>> 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.
>>>
>>> Type "less /var/log/mail.log". Then type "/foo", where "foo" is
>>> a regular expression matching whatever you want to highlight, and
>>> hit return. Now type "F".

>>
>> Thanks Logan, I didn't know less could 'follow'.
>>
>> The other solution by Andreas I like because I can run through a
>> script and use 256 colors for all sort of regexes.

>
> Or use e.g. http://www.vanheusden.com/multitail/ , or
> http://lofimo.anzac.at/ or another log-analyser


That's it! THankyou.

--
Troy Piggins
,-o
o ) Ubuntu linux 6.06 http://ubuntu.com RLU#415538 http://counter.li.org
`-o uptime: 09:43:19 up 20 days,15:12,2 users,load average:0.00,0.01,0.00
Reply With Quote
  #8  
Old 07-08-2009, 04:00 PM
Junior Member
 
Join Date: Jul 2009
Posts: 1
Default Re: tail with color?

For bash I was not able to use the parameters for an alias. Therefor I created a function:

t() {
tail -f -n5000 $1 | perl -pe "s/$2/\e[1;31;43m$&\e[0m/g"
}

This function will tail the file given as parameter 1 and highlight the text given as parameter 2.
Example:
t myLog.log INFO

Martijn de Bruijn
Reply With Quote
Reply

Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert 8Bits RGB Pixels to Palette Color Index and Color LUTs for Icon Image Seqence santhilak DICOM 0 07-01-2009 04:28 PM
COLOR changes color of entire screen unix MS-DOS 9 11-05-2008 12:02 PM
HP OJ d145 color ink out error replace color ink cartridge message unix Hewlett Packard 32 10-04-2007 11:57 PM
[TC] How to use color constant ( >=8 ) as background color ? unix MS-DOS 5 10-01-2007 06:11 AM
Howto change the font color of just a certain website to my choice of color? unix Mozilla 13 05-16-2006 08:05 AM


All times are GMT. The time now is 10:46 AM.