I tried this script to compare two csv files:
import csv
file1 = open("1.csv", "r")
reader1 = csv.reader(file1)
reader1.next()
file2 = open("2.csv", "r")
reader2 = csv.reader(file2)
reader2.next()
file3 = open("file3.txt", "w")
file4 = open("file4.txt", "w")
file1.seek(0, 0)
file2.seek(0, 0)
list1 = file1.readlines()
list2 = file2.readlines()
for i in list1:
for j in list2:
if i == j:
file3.write(i)
file3.write(j)
else:
file4.write(i)
file4.write(j)
continue
and the output I am getting with headers included and plus the mismatched files are repeating. for eg, if my 1.csv contains
Name Salary
A 20000
B 15000
C 10000
2.csv contains
Name Salary
A 40000
D 10000
B 15000
C 9000
output should be
file3: B 15000 B 15000
file4: A 20000 A 40000
C 10000 C 9000
------(no D in 1.csv) D 10000