-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiffmin.py
executable file
·49 lines (42 loc) · 1.11 KB
/
diffmin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
'''
Show lines in the second file that aren't in the first file to stdout.
All output that isn't file content goes to stderr.
'''
from __future__ import print_function
import sys
def echo0(*args, **kwargs):
# PRint eRRoR
print(*args, file=sys.stderr, **kwargs)
return True
def usage():
echo0(__doc__)
if len(sys.argv) < 3:
usage()
echo0("Error: You must specify two files.")
exit(1)
# NOTE: sys.argv[0] is this script.
fName = sys.argv[1]
docDict = {}
count = 0
with open(fName, 'r') as f:
for lineOriginal in f:
if not lineOriginal:
break
line = lineOriginal.strip()
docDict[line] = True
count += 1
echo0("- read " + str(count) + " line(s)")
f2Name = sys.argv[2]
count = 0
newCount = 0
with open(f2Name, 'r') as f:
echo0("Reading " + f2Name + "...")
for lineOriginal in f:
line = lineOriginal.strip()
if docDict.get(line) is None:
print(lineOriginal.rstrip())
newCount += 1
count += 1
echo0("- read " + str(count) + " line(s)")
echo0("- " + str(newCount) + " new line(s).")