Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- f1 f2 f3 f4 f5
- X Y Z A B
- f1 f2 f3 f4
- A U B W
- #!/usr/bin/env perl -nwa
- use strict;
- use File::Find 'find';
- my @search = qw(X Y Z);
- # if you know in advance that the otherfile isn't
- # huge, you can cache it in memory as an optimization.
- # with any more columns, you want a loop here:
- if ($F[0] eq $search[0]
- and $F[1] eq $search[1]
- and $F[2] eq $search[2])
- {
- my @files;
- find(sub {
- return if not -f $_;
- # verbatim search for the columns in the file name.
- # I'm still not sure what your file-search criteria are, though.
- push @files, $File::Find::name if /Q$F[3]E/ and /Q$F[4]E/;
- # alternatively search for the combination:
- #push @files, $File::Find::name if /Q$F[3]E.*Q$F[4]E/;
- # or search *all* files in the search path?
- #push @files, $File::Find::name;
- }, '/search/path'
- )
- foreach my $file (@files) {
- open my $fh, '<', $file or die "Can't open file '$file': $!";
- while (defined($_ = <$fh>)) {
- chomp;
- # order of fields doesn't matter per your requirement.
- my @cols = split ' ', $_;
- my %seen = map {($_=>1)} @cols;
- if ($seen{$F[3]} and $seen{$F[4]}) {
- print join(' ', $F[0], @cols[1,2]), "n";
- }
- }
- close $fh;
- }
- } # end if matching line
- ## perl code to do some dirty work
- for my $line (`grep 'X Y Z' myhugefile`) {
- chomp $line;
- my ($a, $b, $c, $d, $e) = split(/ /,$line);
- my $cmd = 'grep -P "' . $d . ' .+? ' . $e .'" otherfile';
- for my $from_otherfile (`$cmd`) {
- chomp $from_otherfile;
- my ($oa, $ob, $oc, $od) = split(/ /,$from_otherfile);
- print "$a $ob $ocn";
- }
- }
Add Comment
Please, Sign In to add comment