<p>Hi all,</p>

<p>I&#39;m dealing with a fasta file with spaces at the end of line, which caused the problem. I didn&#39;t find a suitable way to remove them. Please kindly tell me the appropriate command for removing them?</p>

Oh my gawk!

All previous solutions would risk modifying your fasta header as well. This one will not.

    gawk 'BEGIN{line=0}{ if ($0 !~/^>/ && $0 ~/ +/ ) {gsub(/ +/, //); line++} print}END{print line" lines with white spaces treated" > "/dev/stderr"}' myfasta.fa >output.fa

If you only want to remove the spaces at the end of the lines:

    gawk 'BEGIN{line=0}{ if ($0 !~/^>/ && $0 ~/ +$/ ) {gsub(/ +$/, //); line++} print}END{print line" lines with white spaces treated" > "/dev/stderr"}' myfasta.fa>output.fa