‘tail -f’ with highlighting
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$1 33[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$1 33[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$1 33[0m 07/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 votes, average: 3.5 out of 5)
May 27th, 2005 at 9:37 am
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.
July 5th, 2005 at 4:59 pm
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.