I have two csv files that are greater that 250K lines and would like to compare some data values. I tried to read file2 into an array and grep for each value of file1…works, but is very slow and inefficient. Both files can be sorted on the data value to be verified.
Here is what I am thinking about doing, but not sure how to do the file handle to step to the next line. (This is just rough sudo code)
Here is what I am thinking about doing, but not sure how to do the file handle to step to the next line. (This is just rough sudo code)
Code:
While <FILE1>
$linefile1 = $_
($valF1a,$valF1b) = split(/,/, $linefile1)
##Not sure how to do <FILE2>
<FILE2>
$linefile2 = $_
($valF2a,$valF2b) = split(/,/, $linefile2)
## Here is the logic I would like to use
if ($valF2a < $valF1a) {
# Not sure if I have a match
Read next line of <FILE2>
} elsif ( $valF2a == $valF1a ) {
# Had a match
Print "Match on $valF1a\n"
Read next line of <FILE1>
} elseif ($valF2a > $valF1a) {
# There was no match for $valF1a
print "$valF1a no match in file2"
Read next line of <FILE1>
}