[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]



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


&gt;&gt;&gt;&gt;&gt; &quot;Armsby&quot; == Armsby John-G &lt;Armsby&gt; writes:

[...]

    Armsby&gt; 1.  find *.html files (recurse) in a particular
    Armsby&gt; folder. pipe it to: 2.  grep -i 'verified' pipe it to: 3.
    Armsby&gt; grep 04 4.  Print the path and filename of the file which
    Armsby&gt; 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&amp;&amp;$v&amp;&amp;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(&quot;**/*.html&quot;){|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&amp;&amp;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, &quot;&lt;&quot;, $file ) ) {
    warn &quot;Can't open '$file': $!\n&quot;;
    next;
  }

  while( &lt;CUR&gt; ) {
    $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                | &quot;If you find my answers frightening,       __`'/|
fletch at phydeaux.org|  Vincent, you should cease askin'          \ o.O'
                      |  scary questions.&quot; -- 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>