I have a requirement that i have two files, one is input file and another is log file(both will contain the same data mostly). I need to compare these two files and if any difference found then those lines should be write to another file(3rd file).

I done googling, but I am able to find only two files comparison which returns true or false.

Has any one have idea? please help me.

thx & rgds,

Simple read the use file.readlines() on both files to give you 2 arrays

so something like this

f1 = open("file1.txt", "r")
f2 = open("file2.txt", "r")

fileOne = f1.readlines()
fileTwo = f2.readlines()
outFile = open("results.txt", "w")
x = 0
for i in fileOne:
   if i != fileTwo[x]:
      outFile.write(i+" <> "+fileTwo[x])
   x += 1


something along those lines


Of course, you'll have to do it the other way too - to look through file2 to be sure everything there is also in file1.

This question has already been answered. Start a new discussion instead.