Created
September 7, 2016 04:51
-
-
Save dumpmycode/0fd5b8844e11df364976a277d9d898e4 to your computer and use it in GitHub Desktop.
File compare
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
| #!/usr/bin/env python | |
| # author:op | |
| # this script tries to loop every line in file1 and compare it to all lines in file2 | |
| # spits out what's not matching | |
| import argparse | |
| parser = argparse.ArgumentParser(description='Find difference between file1.txt and file2.txt') | |
| parser.add_argument('filename1') | |
| parser.add_argument('filename2') | |
| args = parser.parse_args() | |
| with open(args.filename1,'r') as f1: | |
| if '\r\n' in f1.read(): | |
| f1.seek(0) | |
| f1list = f1.read().split('\r\n') | |
| else: | |
| f1.seek(0) | |
| f1list = f1.read().split('\n') | |
| with open(args.filename2,'r') as f2: | |
| if '\r\n' in f2.read(): | |
| f2.seek(0) | |
| f2list = f2.read().split('\r\n') | |
| else: | |
| f2.seek(0) | |
| f2list = f2.read().split('\n') | |
| #print f1list[0:5] | |
| #print ('=================================================================') | |
| #print f2list[0:5] | |
| for i in f1list: | |
| if i not in f2list: | |
| print i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment