Your sed command runs the risk of removing internal Ns that occur before/after line breaks in the sequence. To avoid that you need to linearize the sequence first. It also creates an undesirable empty line between the definition line and the sequence.
This revision avoids all that. It linearizes the record (awk) then converts it to a 2-line fasta record (tr) then removes the leading and trailing N (sed -- I use N instead of n, because typically my Ns are capitalized; you can handle both by substituting [Nn]), then it reformats (fold) the long sequence line into lines of 80 nt width. Make sure you use a width longer than the length of your longest definition line, otherwise it will break those deflines at 80 characters too.
awk '/^>/ {printf("%s%s\t",(N>0?"\n":""),$0);N++;next;} {printf("%s",$0);} END {printf("\n");}' my.fasta | tr "\t" "\n" | sed -r '/^>/! s/N+$|^N+//g' | fold -w 80 > my.Ntrimmed.fasta
Thank you everyone.
This request was to help with submission of genome assemblies to Genbank. They ask that the terminal Ns (gaps) be removed from the ends of contigs. However, I have found that if you simply leave them on they will remove them as part of their process.
stacy734 : While that may be the case since you asked this question in the first place can you please test the posted answers and accept any/all those that work. This would benefit future users who will find this thread by searching.
In fact, this no longer works, so you need one of the other solutions.