[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
- <!--x-content-type: text/plain --> "http://www.w3.org/TR/html4/loose.dtd">
- <!--x-date: Tue Mar 15 09:43:18 2005 -->
- <!--x-from-r13: Xbua.Oezfol ng zbgbebyn.pbz (Oezfol Xbua-U16665) -->
- <!--x-message-id: [email protected] -->
- <!--x-subject: [ale] need a simple shell script -->
- <li><em>date</em>: Tue Mar 15 09:43:18 2005</li>
- <li><em>from</em>: John.Armsby at motorola.com (Armsby John-G16665)</li>
- <li><em>subject</em>: [ale] need a simple shell script</li>
John
-----Original Message-----
From: ale-bounces at ale.org [<a rel="nofollow" href="mailto:ale-bounces">mailto:ale-bounces</a> at ale.org] On Behalf Of Fletch
Sent: Monday, March 14, 2005 10:46 PM
To: Atlanta Linux Enthusiasts
Subject: Re: [ale] need a simple shell script
>>>>> "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
_______________________________________________
Ale mailing list
Ale at ale.org
<a rel="nofollow" href="http://www.ale.org/mailman/listinfo/ale">http://www.ale.org/mailman/listinfo/ale</a>
</pre>
<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<hr>
<!--X-Follow-Ups-End-->
<!--X-References-->
<!--X-References-End-->
<!--X-BotPNI-->
<ul>
<li>Prev by Date:
<strong><a href="msg00270.html">[ale] Don't trust Yast!</a></strong>
</li>
<li>Next by Date:
<strong><a href="msg00272.html">[ale] OT: How to block HTTP 1.0</a></strong>
</li>
<li>Previous by thread:
<strong><a href="msg00264.html">[ale] need a simple shell script</a></strong>
</li>
<li>Next by thread:
<strong><a href="msg00272.html">[ale] OT: How to block HTTP 1.0</a></strong>
</li>
<li>Index(es):
<ul>
<li><a href="maillist.html#00271"><strong>Date</strong></a></li>
<li><a href="threads.html#00271"><strong>Thread</strong></a></li>
</ul>
</li>
</ul>
<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
</body>
</html>