Hello, brothers!

Strange that noone posted this yet, because it seems to be rather useful CUFP. Simple as it sounds: tail -f combined with grep, even with grep -E.

#!/usr/local/bin/perl -w use strict; my $usage = "Usage: gtail <filename> <options for grep>\n"; my $file = shift or die $usage; @ARGV or die $usage; open(TAIL, "tail -f $file|") or die "Can't pipe from tail: $!"; open(GREP, "|grep @ARGV") or die "Can't pipe to grep: $!"; select((select(GREP), $|=1)[0]); while(<TAIL>) { print GREP $_; }

Replies are listed 'Best First'.
Re: grep'ed tail
by b10m (Vicar) on Apr 25, 2005 at 13:40 UTC
    Strange that noone posted this yet, because it seems to be rather useful CUFP.

    Maybe noone posted it, for most people have no problem with actually typing: tail -f /file | grep something?

    I fail to see why this would be prefered over the manual way...

    --
    b10m

    All code is usually tested, but rarely trusted.

      Hmm, really simple, thanks.
      Maybe it's because I came from Windows environment, where chains of piped programs and shell programming aren't used much...

    A reply falls below the community's threshold of quality. You may see it by logging in.