usr bin python import re infile open teststat small count linearray sr

 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
#!/usr/bin/python
import re
infile = open('./teststat.small','r')
count=0
# linearray=['src','dst','bytes','port','port']
finarray=[]
# array="1,0.0.0.0,255.255.0.0,0,0".split(',')
infile.readline()
while 1:
line=infile.readline();
if not line :
break
linearray=line.replace('\n','').split(',');
if re.match(r'^0.0.0.[0-9][0-9]?[0-9]?',linearray[1]):
count=count+1;
if len(finarray)==0 :
finarray.append([linearray[1],linearray[2],long(linearray[0])])
for item in finarray:
# print 'current item: ', item, '\n';
# print 'current linearray:', linearray, '\n';
tmp = raw_input('pause')
if item[0]==linearray[1]:
item[2]=item[2]+long(linearray[0]);
# print 'summed\n';
# tmp = raw_input('pause');
break
elif item[0]!=linearray[1]:
print '\n', item[0], ' != ',linearray[1], '\n';
finarray.append([linearray[1],linearray[2],long(linearray[0])]);
print 'appended\n';
print finarray, ' <<----\n';
# tmp = raw_input('pause')