Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

grep'ed tail

by maard (Pilgrim)
on Apr 25, 2005 at 13:06 UTC ( [id://451171]=CUFP: print w/replies, xml ) Need Help??

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://451171]
Approved by b10m
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-29 09:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found