色付き tail2012年10月25日 10時58分42秒

特定のキーワードが tail で流れていて、目視では見つけられない。調べてみたら、以下の方法があった。どうもあちらこちらでミラーされていて元はどこだか判らない。

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

colored tail で検索したと思う。