Python3
#!/usr/bin/env python3
import sys
def make_id_dict(f):
d = {}
for line in open(f):
k, v = line.split()
if k in d:
d[k] += [ v ]
else:
d[k] = [ v ]
return d
filename1 = sys.argv[1]
filename2 = sys.argv[2]
dict1 = make_id_dict(filename1)
dict2 = make_id_dict(filename2)
for key in sorted(dict1):
for i, value1 in enumerate(dict1[key]):
value2 = dict2[key][i]
if value1 == value2:
result = 'match'
else:
result = 'mismatch'
print(key, value1, value2, result)
Salvar como script match-files-by-ids.py
, em seguida, chamar:
$ python3 match-files-by-ids.py File1 File2
1 12 13 mismatch
1 13 13 match
2 15 15 match
2 16 17 mismatch
4 15 15 match
4 18 18 match