-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_key_cat.py
30 lines (28 loc) · 957 Bytes
/
new_key_cat.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
import sys
#open the existing presentation file
#Make a list of all the keys
#data_file will normally be
#rm_rnb_history_pres.cs
def make_key_list(data_file):
list2 = []
with open(data_file) as f:
for row in f:
#there are non-separator commas, but since the key is in the
#first field, we'll be fine
list2.append(row.split(",")[0])
return list2
#Now, as each line comes in from stdin only output it
#if its key isn't in the list
def new_key_cat(test_file):
#print("entered new_key_cat", file=sys.stderr)
existing_key_list = make_key_list("rm_rnb_history_pres.csv")
if(test_file==""):
f = sys.stdin
else:
f = open(test_file)
for line in f:
#print("working on line" + line, file=sys.stderr)
if(line.split(",")[0] not in existing_key_list):
#print(line)
sys.stdout.write(line)
#print(line, file=sys.stderr)