-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathremove_lines.py
More file actions
71 lines (60 loc) · 2.05 KB
/
remove_lines.py
File metadata and controls
71 lines (60 loc) · 2.05 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import sys
from SFF import SFFMessage
if __name__ == "__main__":
if(len(sys.argv) < 3):
print "Usage: %s <inputfile> <outputfile> <11-bit CAN ID>" % (sys.argv[0])
print "Example1: %s input.dat output.dat 0025" % (sys.argv[0])
print "Example2: %s input.dat output.dat 0025,0026,0027" % (sys.argv[0])
print "Example3: %s input.dat output.dat 0025-02FF" % (sys.argv[0])
sys.exit(1)
#search types
#1 == single ID
#2 == multi-id
#3 == range
wid_search = 1
wids = []
low = 0
high = 0
input_file = sys.argv[1]
output_file = sys.argv[2]
find_wid = sys.argv[3]
if(find_wid.find(',') != -1):
ids = find_wid.split(",")
for wid in ids:
wids.append(wid.strip())
wid_search = 2
elif(find_wid.find("-") != -1):
ids = find_wid.split("-")
low = int(ids[0].strip(), 16)
high = int(ids[1].strip(), 16)
wid_search = 3
#input file to read debug lines from
f = file(input_file, "r")
msgs = []
count = 0
for line in f:
msg = SFFMessage(line)
if(msg.wid != 0):
if(wid_search == 1):
if(msg.wid != find_wid):
count += 1
#msgs.append(msg)
msgs.append(line.strip())
elif(wid_search == 2):
if(msg.wid not in wids):
count += 1
#msgs.append(msg)
msgs.append(line.strip())
elif(wid_search == 3):
wid = int(msg.wid, 16)
if(wid <= low and wid >= high):
count += 1
#msgs.append(msg)
msgs.append(line.strip())
f.close()
#output file to write certain lines out
f = file(output_file, "w")
for found in msgs:
f.write(str(found) + '\n')
f.close()
print "Found %d messages that do not match %s" % (count, sys.argv[3])