[ale] dreaded spaces in file names....
Fletch
fletch at phydeaux.org
Mon Jan 19 22:25:26 EST 2004
>>>>> "John" == John Wells <jb at devsea.com> writes:
[...]
John> locate txt | grep '\.txt$' | xargs grep 'mypattern'
locate txt | grep '\.txt$' | perl -ne 'system("grep", "mypattern", $_)'
Of course one could do it all in perl.
#!/usr/bin/perl
my $pattern = shift;
$pattern = qr/$pattern/;
open( LOCATE, "locate txt |" )
or die "can't open pipe from locate: $!\n";
while( <LOCATE> ) {
next unless /\.txt$/;
my $file = $_;
unless( open( CUR, $_ ) ) {
warn "Can't open $_: $!\n";
next;
}
while( <CUR> ) {
print "$file: $_" if /$pattern/;
}
close( CUR );
}
close( LOCATE );
exit 0;
__END__
--
Fletch | "If you find my answers frightening, __`'/|
fletch at phydeaux.org | Vincent, you should cease askin' \ o.O'
| scary questions." -- Jules =(___)=
| U
More information about the Ale
mailing list