Skip to content

Instantly share code, notes, and snippets.

@tmpbook
Last active January 10, 2018 07:02
Show Gist options
  • Save tmpbook/f7b72cc129f041b7adcfb1280a78f852 to your computer and use it in GitHub Desktop.
Save tmpbook/f7b72cc129f041b7adcfb1280a78f852 to your computer and use it in GitHub Desktop.
Find the different lines between two files | 接受两个参数,第一个是大文件,第二个是小文件,将小文件没有的行输出到 diff.txt 文件中
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import sys
def file_to_list(file):
with open(file) as f:
content = f.readlines()
return content
if __name__ == '__main__':
if len(sys.argv) == 3:
pass
else:
print '''
Need two params:
#1 big file's name
#2 small file's name
'''
sys.exit(-1)
_, big_file, small_file = sys.argv
big_content_list = file_to_list(big_file)
small_content_list = file_to_list(small_file)
for item in big_content_list:
if item in small_content_list:
pass
else:
with open('diff.txt', 'a') as diff:
diff.write(item)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment