I need your help because after some long research I didn't find the appropriate answer to my problems.
I have 2 files which contain some information. Some of this information are similar others are different. The first file is sorted the second one is not.
I tried to use the difflib but it doesn't work in my case , apparently.
Example
File 1 :
customerID: aa
companyName: AA
contacts: AAAA AAAA <aa@aa.fr>
File 2 :
customerID: zz
username: z.z
contacts: ZZZ ZZZ <zz@zz.com>
I need to find if the customerID is the same
Here is my code :
import sys
import string
import difflib
def changes(file1, file2):
# opening the 2 files which we need to compare
master = open(file1, 'r')
slave = open(file2, 'r')
# searching diff
diff = difflib.unified_diff(master.readlines(),slave.readlines())
t = ''.join(diff)
print (t)
def main(argv=2):
print (sys.argv[1])
print (sys.argv[2])
if argv == 2:
changes(sys.argv[1], sys.argv[2])
else:
print ("This program need 2 files")
exit (0)
return 0
if __name__ == '__main__':
status = main()
sys.exit(status)
Edit : The file are txt that i have formated like this myself.