text: user982: I have a multifasta file containing several genes from a genomic island. I want to know the total length of this island. How can I do this?
  
  user929: Here’s a function that I keep around for calculating the individual lengths of fasta sequences
  falens(){
  awk '/^>/ {if (seqlen){print seqlen}; print ;seqlen=0;next; } { seqlen += length($0)}END{print seqlen}' $1
  }
  
  And one I use for summing a column of numbers
  sum(){
  awk '{ sum += $1 } END { print sum}'
  }
  
  You can combine these by piping the output to do the sum for you:
  falens myseqs.fa | grep -v “>” | awk '{ sum += $1 } END { print sum}'
  
  (Can’t test this myself currently as I’m not at my laptop, but it’s based on 2 functions that work normally)
  
  user57: grep -v ">" multi.fasta | tr -d '\n' | wc -c
  
  
  grep -v ">" find all non header lines (i.e. without ">")
  tr -d '\n' delete all newlines
  wc -c count all characters
  
  
original_text: 982: <p>I have a multifasta file containing several genes from a genomic island. I want to know the total length of this island. How can I do this?</p>
   929: <p>Here’s a function that I keep around for calculating the individual lengths of fasta sequences</p>
  
  <pre><code>falens(){
  awk '/^&gt;/ {if (seqlen){print seqlen}; print ;seqlen=0;next; } { seqlen += length($0)}END{print seqlen}' $1
  }
  </code></pre>
  
  <p>And one I use for summing a column of numbers</p>
  
  <pre><code>sum(){
  awk '{ sum += $1 } END { print sum}'
  }
  </code></pre>
  
  <p>You can combine these by piping the output to do the sum for you:</p>
  
  <pre><code>falens myseqs.fa | grep -v “&gt;” | awk '{ sum += $1 } END { print sum}'
  </code></pre>
  
  <p>(Can’t test this myself currently as I’m not at my laptop, but it’s based on 2 functions that work normally)</p>
   57: <pre><code>grep -v "&gt;" multi.fasta | tr -d '\n' | wc -c
  </code></pre>
  
  <ul>
  <li><code>grep -v "&gt;"</code> find all non header lines (i.e. without ">")</li>
  <li><code>tr -d '\n'</code> delete all newlines</li>
  <li><code>wc -c</code> count all characters</li>
  </ul>
  