Sunday, January 08, 2017

Find difference between two text files in Python

#!/usr/bin/python
import difflib, sys

file1 = sys.argv[1]
file2 = sys.argv[2]

diff = difflib.unified_diff ( open(file1).readlines(), open(file2).readlines(), fromfile=file1, tofile=file2 )

strings = list()

for line in diff:
    strings.append(line.replace('\n', ''))

for string in strings:
    print(string)