[ale] need a simple shell script
Fletch
fletch at phydeaux.org
Mon Mar 14 22:53:22 EST 2005
>>>>> "Armsby" == Armsby John-G <Armsby> writes:
[...]
Armsby> 1. find *.html files (recurse) in a particular
Armsby> folder. pipe it to: 2. grep -i 'verified' pipe it to: 3.
Armsby> grep 04 4. Print the path and filename of the file which
Armsby> meets criteria 1,2,3.
The oneliner run from zsh (looks under .; change to /foo/**/*.html(.)
to look under /foo ):
perl -lne '$f++if/04/;$v++if/verified/i;$f&&$v&&print$ARGV;($f,$v)=()if eof' **/*.html(.)
Then there's the almost equivalent Ruby oneliner (also looks under .;
uses Ruby's internal glob rather than the shell's):
ruby -e 'Dir.glob("**/*.html"){|n|File.open(n){|c|f,v=nil,nil;c.each{|l|f=1if l=~/04/;v=1if l=~/verified/i};puts n if f&&v}}'
And the longer pure perl:
#!/usr/bin/perl
use File::Find qw( find );
my @files;
find(sub{push @files, $File::Find::name if -f and /\.html/}, @ARGV);
for my $file ( @files ) {
my( $has_04, $has_verfied );
local( *CUR );
unless( open( CUR, "<", $file ) ) {
warn "Can't open '$file': $!\n";
next;
}
while( <CUR> ) {
$has_04 = 1 if /04/;
$has_verified = 1 if /verified/i;
}
close( CUR );
print $file if $has_04 and $has_verified;
}
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