Skip over all lines in a data file before and including a regular string in a loop in R
<p>I have an instrument that produces data files which contain a large amount of header information. I want to read many files in at a time and <code>rbind</code> them together. To read these in successfully I have been using the following loop and skip to deal with the header information:</p>

<pre><code>df &lt;- c()
for (x in list.files(pattern="*.cnv", recursive=TRUE)) {
u &lt;-read.table(x, skip=100)
      df &lt;- rbind(df, u)
}
</code></pre>

<p>Here is an example of what the datafile with 5 lines to skip looks like:</p>

<pre><code># Header information
# Header information
# Header information
# Header information
# Header information
*END*
      0.571    26.6331     8.2733    103.145     0.0842  -0.000049  0.000e+00
      0.576    26.6316     8.2756    103.171     0.3601  -0.000049  0.000e+00
      0.574    26.6322     8.2744    103.157     0.3613  -0.000046  0.000e+00
</code></pre>

<p>The issue is that the number of lines to skip is dynamic and I would like to come up with a generalized solution. Fortunately, every file ends with this:</p>

<pre><code>*END*
</code></pre>

<p>So my question is, how can I read in a file with the above that skips over all lines before and includes the <code>*END*</code> line? This likely would take place before <code>rbind</code>-ing them together.</p>