色付き 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 で検索したと思う。

コメント

コメントをどうぞ

※メールアドレスとURLの入力は必須ではありません。 入力されたメールアドレスは記事に反映されず、ブログの管理者のみが参照できます。

※なお、送られたコメントはブログの管理者が確認するまで公開されません。

名前:
メールアドレス:
URL:
コメント:

トラックバック

このエントリのトラックバックURL: http://uyota.asablo.jp/blog/2012/10/25/6611957/tb

※なお、送られたトラックバックはブログの管理者が確認するまで公開されません。