Does anybody know what is the best way to compare the contents of 2 csv files and report the identical rows.
By identical i mean, records which have the same values
I think this is the actual code of which Lord Vader speaks:
#!/usr/bin/php
$strFile1 = $argv[1];
$strFile2 = $argv[2];
function parseData($strFilename) {
$strAllData = file($strFilename);
foreach($strAllData as $intLineNum => $strLineData) {
$arrLineData = explode(',',$strLineData);
}
return $arrLineData;
}
$arrFile1 = parseData($strFile1);
$arrFile2 = parseData($strFile2);
$intRow = 0;
foreach($arrFile1 as $intKey => $strVal) {
if(!isset($arrFile2[$intKey]) || ($arrFile2[$intKey] != $strVal)) {
exit("Column $intKey, row $intRow of $strFile1 doesn't match\n");
}
$intRow++;
}
print "All rows match fine.\n";
?>