random technical thoughts from the Nominet technical team

‘tail -f’ with highlighting

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 3.5 out of 5)
Loading ... Loading ...
Posted by dmitri on May 26th, 2005

This is a tip I’ve picked up at this link. It is in
Russian though.

If you want to highlight something when doing ‘tail -f’ you can use the
following command:

tail -f /var/log/logfile | perl -p -e
's/(something)/33[7;1m$133[0m/g;'

or if your terminal supports colours, e.g. linux terminal, you can use
this:

tail -f /var/log/logfile | perl -p -e
's/(something)/33[46;1m$133[0m/g;'

and if you want it to beep on a match use this:

tail -f /var/log/logfile | perl -p -e
's/(something)/33[46;1m$133[0m07/g;'

If you find that perl is too heavy for this you can use sed:

tail -f /var/log/logfile | sed
"s/(something)/^[[46;1m1^[[0m/g"

Note, that in the last example you have to actually type “cntl-v
cntl-[” in place of “^[”

For the full list of control characters on Linux you can look at ‘man
console_codes’.

2 Responses

  1. jay Says:

    I should like to point out that programmers who learnt their craft on ANSI terminals in the 70s and 80s will of course remember this. Nice to see the younger generation catching up.

  2. Daniel R Says:

    I’m currently writing on-call rota management for Nagios. Mail me if interested. It’ll be under the same license (GPL) as Nagios too.

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

Recent Posts

Highest Rated

Categories

Archives

Meta: