[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
- <!--x-content-type: text/plain -->
- <!--x-date: Mon Mar 14 22:53:22 2005 -->
- <!--x-from-r13: syrgpu ng culqrnhk.bet (Tyrgpu) -->
- <!--x-message-id: [email protected] -->
- <!--x-reference: [email protected] --> "http://www.w3.org/TR/html4/loose.dtd">
- <!--x-subject: [ale] need a simple shell script -->
- <li><em>date</em>: Mon Mar 14 22:53:22 2005</li>
- <li><em>from</em>: fletch at phydeaux.org (Fletch)</li>
- <li><em>in-reply-to</em>: <<a href="msg00259.html">[email protected]</a>> (Armsby John-G's message of "Mon, 14 Mar 2005 16:52:13 -0500")</li>
- <li><em>references</em>: <<a href="msg00259.html">[email protected]</a>></li>
- <li><em>subject</em>: [ale] need a simple shell script</li>
[...]
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
</pre>
<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<hr>
<!--X-Follow-Ups-End-->
<!--X-References-->
<ul><li><strong>References</strong>:
<ul>
<li><strong><a name="00259" href="msg00259.html">[ale] need a simple shell script</a></strong>
<ul><li><em>From:</em> John.Armsby at motorola.com (Armsby John-G16665)</li></ul></li>
</ul></li></ul>
<!--X-References-End-->
<!--X-BotPNI-->
<ul>
<li>Prev by Date:
<strong><a href="msg00266.html">[ale] Don't trust Yast!</a></strong>
</li>
<li>Next by Date:
<strong><a href="msg00268.html">[ale] Don't trust Yast!</a></strong>
</li>
<li>Previous by thread:
<strong><a href="msg00263.html">[ale] need a simple shell script</a></strong>
</li>
<li>Next by thread:
<strong><a href="msg00274.html">[ale] need a simple shell script</a></strong>
</li>
<li>Index(es):
<ul>
<li><a href="maillist.html#00267"><strong>Date</strong></a></li>
<li><a href="threads.html#00267"><strong>Thread</strong></a></li>
</ul>
</li>
</ul>
<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
</body>
</html>