<p>My multiple fasta looks something like that:</p>

<p>>chr2_1000-1020</p>

<p>NNNNNNNNNNNNNNNN</p>

<p>>chr2_1-20</p>

<p>NNNNNNNNNNNN</p>

<p>>chr2_20-40</p>

<p>...........</p>

<p>>chr2-200-220</p>

<p> And I want to sort all the sequences in numerical order. Any suggestions? </p>

<p>The following is not the best answer, but I cannot help mentioning my <a href="https://github.com/lh3/foreign/tree/master/sort">alpha-numeric sort</a>, which I use daily. It is modified from unix sort and sorts "chr10,chr2" to "chr2,chr10" and also coordinates in the right way. You can use Pierre's command line to turn fasta into one line, I will just use <a href="https://github.com/lh3/bioawk">bioawk</a> for simplicity:</p>

<pre><code>bioawk -c fastx '{print}' in.fa | sort -k1,1N | awk '{print "&gt;"$1;print $2}'
</code></pre>

<p>where "sort" here is compiled from by modified sort. For me, this alpha-numeric sort has reduced a lot of tedious works related to coordinate sorting.</p>


----------


Edit 2.3.21 by https://www.biostars.org/u/25721/

In the original answer it was `awk -c fastx` instead of `bioawk`, I made that change now.

One might also try `sort -k1,1V` to get a simple natural sort here in case that is of interest.