[951] | 1 | import re |
---|
| 2 | result = open('result.txt').readlines() |
---|
| 3 | length1 = len(result) |
---|
| 4 | |
---|
| 5 | for i in range(0, length1): |
---|
| 6 | result[i] = result[i].replace('- ', '-') |
---|
| 7 | result[i] = result[i].replace('/ ', '/') |
---|
| 8 | result[i] = result[i].replace('[','[ ') |
---|
| 9 | result[i] = result[i].replace(']',' ]') |
---|
| 10 | result[i] = result[i].replace(':',' :') |
---|
| 11 | result[i] = result[i].replace('(','( ') |
---|
| 12 | result[i] = result[i].replace(')',' )') |
---|
| 13 | for i in range(0, length1): |
---|
| 14 | result[i] = result[i].replace('-', ' ') |
---|
| 15 | result[i] = result[i].replace('/', ' ') |
---|
| 16 | |
---|
| 17 | result = result[4:length1] |
---|
| 18 | length2 = len(result) |
---|
| 19 | |
---|
| 20 | # from below for loops, 3 is the total output line numbers and the remainder of i divided by 3 is |
---|
| 21 | # the location of the line tht contains port #, bandwidth, loss, and etc. |
---|
| 22 | ######################################################################## |
---|
| 23 | # in each file, ptmp.txt and rtmp.txt, there are sentences that contain port#, and bandwidth, etc. |
---|
| 24 | # below command lines separates the sentences into words and rearrange them into vector forms and save them into different files, |
---|
| 25 | # repnum and portadd, so that they could be imported into matlab workspace. |
---|
| 26 | |
---|
| 27 | for i in range(0, length2): |
---|
| 28 | if (i%3) == 0: |
---|
| 29 | f = open('ptmp.txt','a') |
---|
| 30 | f.write(str(result[i])+'\n') |
---|
| 31 | f.close() |
---|
| 32 | a = open('ptmp.txt').readlines() |
---|
| 33 | for i in range(0, len(a)): |
---|
| 34 | portadd = a[i] |
---|
| 35 | q = re.split('\s+', str(portadd)) |
---|
| 36 | for j in range(0, len(q)): |
---|
| 37 | s = open('portadd.txt','a') |
---|
| 38 | s.write(str(q[j])+'\n') |
---|
| 39 | s.close() |
---|
| 40 | elif (i%3) == 2: |
---|
| 41 | f = open('rtmp.txt','a') |
---|
| 42 | f.write(str(result[i])+ '\n') |
---|
| 43 | f.close() |
---|
| 44 | f = open('rtmp.txt').readlines() |
---|
| 45 | for i in range(0, len(f)): |
---|
| 46 | repnum = f[i] |
---|
| 47 | p = re.split('\s+', str(repnum)) |
---|
| 48 | for j in range(0, len(p)): |
---|
| 49 | s = open('repnum.txt','a') |
---|
| 50 | s.write(str(p[j])+'\n') |
---|
| 51 | s.close() |
---|
| 52 | |
---|
| 53 | |
---|