There are two csv files, in the first file the third column has a certain number of rows with data, and in the second file the first column has similar data, also in some indefinite amount,
these are presented in the form of md5, for example:
file_1
| column_1 | column_2 | column_3 |
|---|---|---|
| blah blah blah | blah blah blah | aa7744226c695c0b2e440419848cf700 |
| blah blah blah | blah blah blah | 9b34939b137e24f8c6603a54b2305f07 |
| blah blah blah | blah blah blah | ad1172b28f277eab7ca91f96f13a242b |
etc |
file_2
| column_1 | column_2 | column_3 |
|---|---|---|
| 49269f413284abfa58f41687b6f631e0 | blah blah blah | blah blah blah |
| a0879ff97178e03eb18470277fbc7056 | blah blah blah | blah blah blah |
| 9e5b91c360d6be29d556db7e1241ce82 | blah blah blah | blah blah blah |
etc |
Could you tell me please, how can i compare these two columns from two files, i.e. find duplicate values, and if the values are repeated, then display what value is in the first and second csv file.
I tried to take something from this example:
import csv
interesting_cols = [0, 2, 3, 4, 5]
with open("/root/file1.csv", 'r') as file1,\
open("/root/file2.csv", 'r') as file2:
reader1, reader2 = csv.reader(file1), csv.reader(file2)
for line1, line2 in zip(reader1, reader2):
equal = all(x == y for n, (x, y) in enumerate(zip(line1, line2)) if n in interesting_cols)
print(equal)
this example would work well if two files would have only one column each. According to my requirements, I could not implement it in any way, I am very weak in Python. Thank you very much!