title: Remove line breaks in a FASTA file
body: <p>I have a fasta file where the sequences are broken up with newlines.  I'd like to remove the newlines.  Here's an example of my file:</p>
  
  <pre><code>&gt;accession1
  ATGGCCCATG
  GGATCCTAGC
  &gt;accession2
  GATATCCATG
  AAACGGCTTA
  </code></pre>
  
  <p>I'd like to convert it into this:</p>
  
  <pre><code>&gt;accession1
  ATGGCCCATGGGATCCTAGC
  &gt;accession2
  GATATCCATGAAACGGCTTA
  </code></pre>
  
  <p>I found a potential solution <a href="http://seqanswers.com/forums/showthread.php?t=27567" rel="noreferrer">on this site</a>, which looks like this:</p>
  
  <pre><code>cat input.fasta | awk '{if (substr($0,1,1)=="&gt;"){if (p){print "\n";} print $0} else printf("%s",$0);p++;}END{print "\n"}' &gt; joinedlineoutput.fasta
  </code></pre>
  
  <p>However, this places an extra line break between each entry, so file looks like this:</p>
  
  <pre><code>&gt;accession1
  ATGGCCCATGGGATCCTAGC
  
  &gt;accession2
  GATATCCATGAAACGGCTTA
  </code></pre>
  
  <p>I'm an awk noob, but I took a shot at modifying the command.  My guess was the <code>if (p){print "\n";}</code> was the culprit...potentially <code>print "\n"</code> is adding two line breaks.  I couldn't figure out how to add just one newline...this is probably something easy, but like I said, I'm a noob.  Here was my (unsuccessful) solution:</p>
  
  <pre><code>awk '{if (substr($0,1,1)=="&gt;"){print "\n"$0} else printf("%s",$0);p++;}END{print "\n"}' input.fasta &gt; joinedoutput.fasta
  </code></pre>
  
  <p>However, this adds an empty line at the beginning of the file because it's always printing a new line before it prints the first accession number:</p>
  
  <pre><code>{empty line} 
  &gt;accession1
  ATGGCCCATGGGATCCTAGC
  &gt;accession2
  GATATCCATGAAACGGCTTA
  </code></pre>
  
  <p>Anyone have a solution to get my file in the correct format?  Thanks!</p>