Purpose: Find the first floating-point number in the text with the lower three vertical bars in the Sum/avg line
Idea: First use Python to read a line in the text, and then split the string, find the line containing the SUM/AVG keyword, take out the desired result
Text Local:
........
| Msop0 | 8 326 | 99.4 0.3 0.3 0.3 0.9 25.0 | -0.383 |
|--------+-------------+-----------------------------------------+-------------|
| MSPE0 | 8 394 |100.0 0.0 0.0 0.0 0.0 0.0 |-2147483.648 |
|--------+-------------+-----------------------------------------+-------------|
| Muor0 | 8 458 |100.0 0.0 0.0 0.0 0.0 0.0 |-2147483.648 |
|--------+-------------+-----------------------------------------+-------------|
| mvxz0 | 8 435 | 99.8 0.0 0.2 0.2 0.5 25.0 | 0.419 |
|--------+-------------+-----------------------------------------+-------------|
| Mwie0 | 8 376 |100.0 0.0 0.0 0.0 0.0 0.0 |-2147483.648 |
|==============================================================================|
| Sum/avg| 224 11172 | 99.8 0.1 0.1 0.1 0.2 8.5 | -0.089 |
|==============================================================================|
| Mean | 8.0 399.0 | 99.8 0.1 0.1 0.1 0.2 8.5 |-2147483.648 |
| S.D. | 0.0 35.4 | 0.2 0.1 0.2 0.1 0.3 9.0 |-2147483.648 |
| Median | 8.0 394.0 |100.0 0.0 0.0 0.0 0.2 12.5 |-2147483.648 |
'------------------------------------------------------------------------------'
The test procedure is as follows:
>>> ss= ' | Sum/avg| 224 11172 | 99.8 0.1 0.1 0.1 0.2 8.5 | -0.089 | ' >>> SS ' | Sum/avg| 224 11172 | 99.8 0.1 0.1 0.1 0.2 8.5 | -0.089 | ' >>> ss.split (' | ') [', ' sum/avg ', ' 224 11172 ', ' 99.8 0.1 0.1 0.1 0.2 8.5 ', ' -0.089 ', ']>>> ss.split (' | ') [1] = = ' Sum/avg ' true>>> ss.split (' | ') [3] ' 99.8 0.1 0.1 0.1 0.2 8.5 ' >>> ss.split (' | ') [3] [0:5] ' 99.8 ' >>> float (ss.split (' | ') [3] [0:5]) 99.8
Reference program:
f = open ("Ctm_39phn.filt.sys") # Returns a file object line = F.readline () # Call the file's ReadLine () method while line: #print line,< c3/># followed by ', ' will ignore newline character if Line.split (' | ') [1] = = ' Sum/avg ':p rint float (line.split (' | ') [3] [0:5]) # print (line, end = ') # in Python 3 using line = F.readline () f.close ()
Example of a python parsing text file