python skip useless data and read specific line -


my text file has 20 pages long , need print specific data

my text file looks like:

123mcx    version 1.5.0 ld=fri apr 09 08:00:00 mst 2008                12/10/12 11:59:03  ***************************************************************************************   1-       c ==== cells ====                                                                    2-       1 0   1                   $ outside                                                  3-       2 102 -0.001 -1 23 51                                                                4-       c                                                                                    5-       21 3   -4.15e-4 -21                          $ detector                              6-       22 5   -11.34   -22 21                 $ pb                                          7-       23 6   -7.87    -23 22                 $ fe tube                                     8-       c                                                                                    9-       50 7000 -1.7  -51 41                          multiplier bins  att  constant    material   reactions or material-rho*x pairs      1.02400e+00      3        103   time  bins       -i             5.00000e+02 shakes       5.00000e+02   1.06000e+03 shakes       1.06000e+03   1.69000e+03 shakes       1.69000e+03   2.40000e+03 shakes       2.40000e+03   3.19000e+03 shakes       3.19000e+03   4.08000e+03 shakes       4.08000e+03   5.08000e+03 shakes       5.08000e+03   6.19000e+03 shakes       6.19000e+03   7.43000e+03 shakes       7.43000e+03   8.84000e+03 shakes  multiplier bin:   1.02400e+00    3        103                                                                                  time      5.0000e+02   5.54627e-06 0.0004-------- [i need data start here]     1.0600e+03   2.40573e-06 0.0018     1.6900e+03   2.11609e-06 0.0026     2.4000e+03   2.04138e-06 0.0033     3.1900e+03   2.01640e-06 0.0038     4.0800e+03   2.07022e-06 0.0043     5.0800e+03   2.11266e-06 0.0047     6.1900e+03   2.16806e-06 0.0050     7.4300e+03   2.24147e-06 0.0053     8.8400e+03   2.32872e-06 0.0056     1.0400e+04   2.36765e-06 0.0060     1.2200e+04   2.50930e-06 0.0061     1.4100e+04   2.43235e-06 0.0065     1.6400e+04   2.69267e-06 0.0066-----[end] 1analysis of results in tally fluctuation chart bin  (tfc) tally  14 nps =1598425200    print table 160 normed average 7.174350e-05          unnormed history  = 8.85335e-01  estimated error    = 0.0014          estimated variance of variance  = 0.0000 

i need skip data , print need like:

5.0000e+02   5.54627e-06 0.0004 1.0600e+03   2.40573e-06 0.0018 1.6900e+03   2.11609e-06 0.0026 2.4000e+03   2.04138e-06 0.0033 3.1900e+03   2.01640e-06 0.0038 4.0800e+03   2.07022e-06 0.0043 5.0800e+03   2.11266e-06 0.0047 6.1900e+03   2.16806e-06 0.0050 7.4300e+03   2.24147e-06 0.0053 8.8400e+03   2.32872e-06 0.0056 1.0400e+04   2.36765e-06 0.0060 1.2200e+04   2.50930e-06 0.0061 1.4100e+04   2.43235e-06 0.0065 1.6400e+04   2.69267e-06 0.0066 

after need add second column numbers like

(5.54627e-06 +  2.40573e-06 + 2.11609e-06 + ...+ 2.69267e-06) = 3.504897e-05 

please me know how skip data , print want

thank you

use regular expression on each line:

5.0000e+02 5.54627e-06 0.0004 like:

import re  goodlineregex = r'\d+\.\d+e[+-]\d+\s{3}\d+\.\d+e[+-]\d+\s\d+\.\d+'  line in file:      m = goodlineregex.match(line)      if m not none:          do_something(line) 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -