Created
June 27, 2019 15:34
-
-
Save chand1012/5bdf572ec074f9a2eb23b1ad856e4d12 to your computer and use it in GitHub Desktop.
Compares two files and puts their common lines in a file called output.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
def common_item(lista, listb, mode=0): | |
items = [] | |
for x in lista: | |
for y in listb: | |
if x==y: | |
if not mode: | |
return True | |
if mode: | |
items += [x] | |
if not mode: | |
return False | |
if mode: | |
return items | |
f = sys.argv[1] | |
f2 = sys.argv[2] | |
testfileobj = open(f) | |
testfileobj2 = open(f2) | |
testfilelines = testfileobj.readlines() | |
testfile2lines = testfileobj2.readlines() | |
print("Scanning file...") | |
commonlines = common_item(testfilelines, testfile2lines, 1) | |
print("Found {} lines, creating output file...".format(len(commonlines))) | |
output = open("output.txt", "w") | |
for i in commonlines: | |
output.write(i) | |
output.close() | |
print("Done.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment