Use Perl with UNIX tools

Kensuke Kaneko
2010-12-10

Perl is very useful programming language for not only programmers but also system administrators.

Perl has good compatibility with UNIX philosophy - `Make each program do one thing well'. Experienced system administrators use simple tools by combination. But sometimes these long one-liner looks like too complex.

For example, see this command line. Note that `^[' is ESC character.

# tail -f /var/log/messages | sed -e 's/\(error\)/^[[7m\1^[[m^G/'

It works like this: to invert highlighting matching string `error' and send bell.

But I think there are some problems to write literal escape character.

I fixed these problem to write simple filter program by Perl. This is escfilter, simple grep-like tool.

# tail -f /var/log/messages | escfilter --reverse error

I think this approach is bit better than previous way.

See Also

escfilter on gist

Special Thanks

Yuuki Namikawa (@namikawa) was described how to processing log file with escape sequence by sed.

Kato Kazuyoshi (kzys) was improved escfilter script by using Term::ANSIColor.

Writer

Kensuke Kaneko (@kyanny)