Skip to content

Instantly share code, notes, and snippets.

@sc0tt
Last active December 23, 2015 20:09
Show Gist options
  • Save sc0tt/6687945 to your computer and use it in GitHub Desktop.
Save sc0tt/6687945 to your computer and use it in GitHub Desktop.
Performs an outer join type deal on two files. Finds lines in A not found in B and lines in B not found in A
import sys
def getContents(inFile):
return sorted(list(set(inFile.read().split("\n"))), key=lambda k: k.lower())
lFileName = raw_input("Enter the first file name: ") if len(sys.argv) < 2 else sys.argv[1]
with open(lFileName, "r") as left:
leftLines = getContents(left)
rFileName = raw_input("Enter the second file name: ") if len(sys.argv) < 3 else sys.argv[2]
with open(rFileName, "r") as right:
rightLines = getContents(right)
lineList = []
lineList.extend([lnk for lnk in leftLines if lnk not in rightLines])
lineList.extend([lnk for lnk in rightLines if lnk not in leftLines])
print "\n".join(lineList)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment