Skip to content

Instantly share code, notes, and snippets.

@kd7lxl
Created June 16, 2010 20:22
Show Gist options
  • Save kd7lxl/441212 to your computer and use it in GitHub Desktop.
Save kd7lxl/441212 to your computer and use it in GitHub Desktop.
Compares two text files and outputs the differing lines (like diff without the extra stuff)
#!/usr/bin/env python
from sys import argv,exit
def list_strip(list):
new_list = []
for line in list:
if not line.strip():
continue
else:
new_list.append(line.strip())
return new_list
def read_file_to_list(filename):
try:
file = open(filename, 'r')
list = file.readlines()
file.close()
return list_strip(list)
except IOError:
print "Error: %s does not exist." % filename
exit()
def main():
try:
l1 = read_file_to_list(argv[1])
l2 = read_file_to_list(argv[2])
diff = list(set(l1) - set(l2))
print ' '.join(sorted(diff)).strip()
except IndexError:
print 'Please specify two input files.'
exit()
if __name__ == "__main__":
exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment