[951] | 1 | import re |
---|
| 2 | result = open('result.txt').readlines() |
---|
| 3 | length1 = len(result) |
---|
| 4 | for i in range(0, length1): |
---|
| 5 | result[i] = result[i].replace('- ', '-') |
---|
| 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 | for i in range(0, length1): |
---|
| 13 | result[i] = result[i].replace('-', ' ') |
---|
| 14 | result[i] = result[i].replace('/', ' ') |
---|
| 15 | |
---|
| 16 | # from below for loops, 13 is the total output line numbers and the remainder of i divided by 13 is |
---|
| 17 | # the location of the line tht contains port #, bandwidth, loss, and etc. |
---|
| 18 | |
---|
| 19 | for i in range(0,length1): |
---|
| 20 | if (i%13) == 4: |
---|
| 21 | f = open('ptmp.txt','a') |
---|
| 22 | f.write(str(result[i])+'\n') |
---|
| 23 | f.close() |
---|
| 24 | elif (i%13) == 8: |
---|
| 25 | f = open('dual_ptmp.txt','a') |
---|
| 26 | f.write(str(result[i])+'\n') |
---|
| 27 | f.close() |
---|
| 28 | elif (i%13) == 10: |
---|
| 29 | f = open('rtmp.txt','a') |
---|
| 30 | f.write(str(result[i])+ '\n') |
---|
| 31 | f.close() |
---|
| 32 | elif (i%13) == 12: |
---|
| 33 | f = open('dual_rtmp.txt','a') |
---|
| 34 | f.write(str(result[i])+ '\n') |
---|
| 35 | f.close() |
---|
| 36 | |
---|
| 37 | # in each file, ptmp.txt and rtmp.txt, there are sentences that contain port#, and bandwidth, etc. |
---|
| 38 | # below command lines separates the sentences into words and rearrange them into vector forms |
---|
| 39 | # so that they could be imported into matlab workspace. |
---|
| 40 | |
---|
| 41 | o = open('ptmp.txt').readlines() |
---|
| 42 | for i in range(0, len(o)): |
---|
| 43 | portadd = o[i] |
---|
| 44 | q = re.split('\s+', str(portadd)) |
---|
| 45 | s = open('portadd.txt','a') |
---|
| 46 | for j in range(0, len(q)): |
---|
| 47 | s.write(str(q[j])+'\n') |
---|
| 48 | s.close() |
---|
| 49 | |
---|
| 50 | f = open('rtmp.txt').readlines() |
---|
| 51 | for i in range(0, len(f)): |
---|
| 52 | repnum = f[i] |
---|
| 53 | p = re.split('\s+', str(repnum)) |
---|
| 54 | s = open('repnum.txt','a') |
---|
| 55 | for j in range(0, len(p)): |
---|
| 56 | s.write(str(p[j])+'\n') |
---|
| 57 | s.close() |
---|
| 58 | |
---|
| 59 | a = open('dual_rtmp.txt').readlines() |
---|
| 60 | for i in range(0, len(a)): |
---|
| 61 | d_repnum = a[i] |
---|
| 62 | r = re.split('\s+', str(d_repnum)) |
---|
| 63 | s = open('dual_repnum.txt','a') |
---|
| 64 | for j in range(0, len(r)): |
---|
| 65 | s.write(str(r[j])+'\n') |
---|
| 66 | s.close() |
---|
| 67 | |
---|
| 68 | t = open('dual_ptmp.txt').readlines() |
---|
| 69 | for i in range(0, len(t)): |
---|
| 70 | d_portadd = t[i] |
---|
| 71 | q = re.split('\s+', str(d_portadd)) |
---|
| 72 | s = open('dual_portadd.txt','a') |
---|
| 73 | for j in range(0, len(q)): |
---|
| 74 | s.write(str(q[j])+'\n') |
---|
| 75 | s.close() |
---|