Could be written shorter, but I think that this what you want and it will run very quickly (compared with R).#!/usr/bin/perl use warnings; use strict; # this uses a "trick" to open an in memory file # like a file on the disk for testing purposes my $file1 =<<END; 1 19002930 0.74 1 19002931 -0.12 END my $file2 =<<END; 1 19002930 0.84 0.12 0.94 1 19002931 0 -.20 .12 END open (my $fh1, '<', \$file1) or die "$!"; open (my $fh2, '<', \$file2) or die "$!"; my $lineFile1; my $lineFile2; # compare line by line of both files # stop if either file "runs out of lines" # assumes that say: line 232 of file 1 goes with line 232 of file 2 while (defined ($lineFile1=<$fh1>) and defined ($lineFile2=<$fh2>)) { my ($line1Col1, $line1Col2, $line1Col3) = split ' ', $lineFile1; my ($line2Col1, $line2Col2, @file2rest) = split ' ', $lineFile2; if ($line1Col1 == $line2Col1 and $line1Col2 == $line2Col2) { print "$line1Col1 $line1Col2 "; print join" ", grep{ $_>=$line1Col3 }@file2rest; print "\n"; } else { # col1 and col2 didn't match, so we do nothing # you can delete this else clause entirely } } __END__ prints: 1 19002930 0.84 0.94 1 19002931 0 .12
In reply to Re^3: extract values from file if greater than value
by Marshall
in thread extract values from file if greater than value
by mulder4786
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |