I need to compare 2 files columnwise based on primary columns(it could be 1 or multiple columns as a primate key). And it should generate 3 csv files as output - differences , extra records in file1, extra records in file2
Note : tried with sdiff but it doesnt give output as desired
Example :
Here first column is a primary key
file1 :
abc 234 123
bcd 567 890
cde 678 789
file2 :
abc 234 012
bcd 532 890
cdf 678 789
Output files
differences file :
abc,234,123::012
bcd,567::532,890
extra records in file1 :
cde,678,789
extra records in file2
cdf,678,789
If the files comfortably fit in memory, it's quite easy to do with hashes in Perl. For example:
Output:
Note: csv output doesn't normally need to be ordered, so this code doesn't do any sorting.