On Aug 8, 5:40 pm, student.northwest...@gmail.com (Jim Green) wrote:
> Hi,
> I used to use find, a for loop and awk to extract data from a list of
> files returned by find.
>
> Now I want to use file::find  and perl to this.
>
>  use vars qw/*name *dir *prune/;
>  *name   = *File::Find::name;
>  *dir    = *File::Find::dir;
>  *prune  = *File::Find::prune;
>
>  my $directories_to_seach="/home/jim";
>
>   sub wanted;
>
>   # Traverse desired filesystems
>   File::Find::find({wanted => \&wanted}, $directories_to_seach);
>   exit;
>
>   sub wanted {
>   /regex/s
>      && print("$name\n");
>   }
>
> my question is how to do in a native, elegant perl way for my bash
> script?
>
> for file in `find . -name "*pattern*"`
> do
>     zcat $file|awk '$2 == "BP" {print $17 $18}'|\
>     echo
> done

If you just need a quick look via the command line:

perl -MFile::Find -le 'find sub{print $File::Find::name if /
pattern/},"/my/dir" '  \
  | xargs zcat  | perl -lane 'print @F[16,17] if $F[1] eq "BP" '

--
Charles DeRykus


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to