title: Java: How to extract matching lines from a large text file fast?
body: <p>Although aware that there are plenty of offered solutions to my problem <em>in general</em>, 
  I am still not satisfied with the runtime they require in my <em>special</em> case.</p>
  
  <p>Consider a <strong>35G</strong> large <strong>text file</strong> in FASTA format, like this:</p>
  
  <pre>
  >Protein_1 So nice and cute little fella
  MTTKKCLQKFHLESLGKLGDSFLKYAISIQLFKSYENHYEGLPSIKKNKIISNAALFKLG 
  YARKILRFIRNEPFDLKVGLIPSDNSQAYNFGKEFLMPSVKMCSRVK*
  >Protein_2 Fancy incredible description of its function
  MADDSKFCFFLVSTFLLLAVVVNVTLAANYVPGDDILLNCGGPDNLPDADGRKWGTDIGS
  […] etc.
  </pre>
  
  <p>I need to extract the <code>&gt;</code> lines <em>only</em>.</p>
  
  <p>Using <code>grep '&gt;' proteins.fasta &gt; protein_descriptions.txt</code> to achieve this takes only a couple of minutes.</p>
  
  <p>But using Java 7 this is now already running for over 90 minutes:</p>
  
  <pre><code>public static void main(String[] args) throws Exception {
      BufferedReader fastaIn = new BufferedReader(new FileReader(args[0]));
      List&lt;String&gt; l = new ArrayList&lt;String&gt;();
      String str;
      while ((str = fastaIn.readLine()) != null) {
          if (str.startsWith("&gt;")) {
              l.append(str);
          }
      }
      fastaIn.close();
      // …
  }
  </code></pre>
  
  <p>Does anyone have an idea of how to speed this up to <code>grep</code> performance?</p>
  
  <p>Your help will be much appreciated.
  Cheers!</p>