I have a requirement like below:
input1_txt
a
b
c
input2_txt
1|2|3|a|e|f
1|3|4|b|g|h
3|2|4|c|f|h
d|f|g|i|h|j
I am trying to read both input1,input2 and writing into ouput_file
if input1 first column is equal to input2 fouth column then write all input2 to ouput_file.
Code:
read1 = csv.reader(open(input1_txt, 'r')) # read input file 1
write = csv.writer(open(output_file,"w"), delimiter="|", lineterminator="\n")
for row1 in read1:
#print(row1)
read2 = csv.reader(open(input2_file, 'r'), delimiter="|", lineterminator="\n")
for row2 in read2:
#print(row2)
if row1 == row2[4]:
write.writerows(row2)
The expected output is as below: i..e only matched input1 first column and input2 fouth column
1|2|3|a|e|f
1|3|4|b|g|h
3|2|4|c|f|h
This code show how not getting any results.Please advise.