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 ...

+ Reply to Thread
Results 1 to 8 of 8

Thread: tail with color?

  1. 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

  2. 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

  3. 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

  4. 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

  5. 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

  6. 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"

  7. 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

  8. 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 to Thread