Welcome, guest | Sign In | My Account | Store | Cart
import sys
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("file1", help="First file whose lines you want to check")
parser.add_argument("file2", help="Second file, in which you want to search for lines from first file")
args = parser.parse_args()

file1 = open(args.file1)
file2 = open(args.file2)

print "Comparing:"
print args.file1
print "and"
print args.file2
print ""
print "Attempting to find lines in *file1* that are missing in *file2*"
print ""
file1array = file1.readlines()
file2a = file2.readlines()
lengthfile1array = len(file1array)
j=0;
for file1item in file1array:
    j += 1
    sys.stdout.write("Checking line#: %d/" %(j))
    sys.stdout.write("%d   \r" %(lengthfile1array))
    i=0;
    for file2item in file2a:
        if file1item.rstrip() == file2item.rstrip():
            i += 1
            break
        else:
            i += 1
        
        if i == len(file2a):
            print "MISSING LINE FOUND at Line# " + str(j)

Diff to Previous Revision

--- revision 1 2012-06-10 18:27:55
+++ revision 2 2012-06-15 15:45:18
@@ -24,18 +24,13 @@
     j += 1
     sys.stdout.write("Checking line#: %d/" %(j))
     sys.stdout.write("%d   \r" %(lengthfile1array))
-    #print "Checking " + str(j)
     i=0;
     for file2item in file2a:
-        #print "*" + file2item.rstrip()
         if file1item.rstrip() == file2item.rstrip():
-            #print str(i) + " *" + file1item.rstrip() + " vs " + file2item.rstrip() + " found"
             i += 1
             break
         else:
-            #print str(i) + " Checking " + file1item.rstrip() + " vs " + file2item.rstrip()
             i += 1
         
         if i == len(file2a):
-            #print "Reached end - Restarting - i = " + str(i) + " - len(file2item) = " + str(len(file2item))
             print "MISSING LINE FOUND at Line# " + str(j)

History