title: replacing fasta headers gives mismatch
body: <p>probably a simple issue, but I cannot seem to solve it like this.
  I want to replace the headers of a FASTA file. This file is a subset of a larger file, but headers were adjusted in the process. I want to add the original headers since it includes essential information.
  I selected the headers from the subset (subset.fasta) using grep, and used this to match and extract the headers from the original file, giving 'correct.headers'. They are the same number of headers and in the same order, so this should be ok.
  I found the code below which should do what I want according to the description. I've only started learning awk, so I can't really control it, though.</p>
  <pre><code>awk 'NR == FNR { o[n++] = $0; next } /^&gt;/ &amp;&amp; i &lt; n { $0 = &quot;&gt;&quot; o[i++] } 1' correct.headers subset.fasta &gt; subset.correct.fasta
  </code></pre>
  <p>(source: <a href="https://stackoverflow.com/questions/60670383/replace-fasta-headers-using-sed-command">Replace fasta headers using sed command</a>)</p>
  <p>However, there are some 100 more output lines than expected, and there's a shift starting after a couple of million lines.</p>
  <p>My workflow was like this:</p>
  <p>I had a subsetted fasta-file (created by a program extracting certain taxa) where the headers were missing info:</p>
  <pre><code>&gt;header_1 
  read_1
  &gt;header_2 
  read_2 
  ...
  &gt;header_n 
  read_n
  </code></pre>
  <p>I extracted the headers from this subsetted file using grep, giving the subset headers file:</p>
  <pre><code>&gt;header_1
  &gt;header_2
  ...
  &gt;header_n
  </code></pre>
  <p>I matched the first part of the header to extract the original headers from the non-subsetted file using grep:</p>
  <pre><code>&gt;header_1 info1
  &gt;header_2 info2
  ...
  &gt;header_n info_n
  </code></pre>
  <p>giving the same number of headers, matching order, etc.</p>
  <p>I then used this file to replace the headers in the subset with the original ones using above awk line, but this gives a mismatch at a certain point and adds additional lines.</p>
  <p>result</p>
  <pre><code>&gt;header_1 info1
  read_1
  &gt;header_2 info2
  read_2
  ...
  &gt;header_x info_x
  read_n
  </code></pre>
  <p>Where/why does it go wrong?</p>
  <p>Thanks!</p>