Last active
December 23, 2015 20:09
-
-
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
This file contains 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 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