Using python to extract a few lines from a data file
<p>I have a large file which has an enormous of data in it. I need to extract 3 lines every 5000 or so lines. The format of the data file is as follows:</p>

<p>...</p>

<pre><code>O_sh          9215    1.000000   -2.304400   
 -1.0680E+00  1.3617E+00 -5.7138E+00  
O_sh          9216    1.000000   -2.304400  
 -8.1186E-01 -1.7454E+00 -5.8169E+00  
timestep    501      9216         0         3    0.000500  
   20.54      -11.85       35.64      
  0.6224E-02   23.71       35.64      
  -20.54      -11.86       35.64      
Li               1    6.941000    0.843200
  3.7609E-02  1.1179E-01  4.1032E+00
Li               2    6.941000    0.843200
  6.6451E-02 -1.3648E-01  1.0918E+01
</code></pre>

<p>...</p>

<p>What I need is the the three lines after the line that starts with "timestep" so in this case I need the 3x3 array:</p>

<pre><code>   20.54      -11.85       35.64      
  0.6224E-02   23.71       35.64      
  -20.54      -11.86       35.64  
</code></pre>

<p>in an output file for each time the word "timestep" appears. </p>

<p>Then I need the average of all those arrays in just one array. Just one array consisting of the average value of each element in the same position in every array for the whole file.
I've been working on this for a while, but I haven't been able to extract the data correctly yet.</p>

<p>Thanks so much, and this is not for homework. You're advice will be helping the progress of science! =)</p>

<p>Thanks,</p>
