Amazing GNU sort

Originally published on my old Blogger blog on September 17, 2013. Read the original post and its comments.

I just came across this on Biostar: http://www.biostars.org/p/64687/

Question: How to sort bed format file

2

Is there any tools or commands to sort bed format file? The correct order is chr1, chr2, chr3, chr4,..., chr22, chrX, chrY.

3

GNU sort can now sort in alpha-numeric order. See option "-V, --version-sort" of the following version "sort (GNU coreutils) 8.17".
Here is an example:

$ echo -e "chr10\t1\t2\tA\nchr2\t1\t2\tB\nchr1\t1\t2\tC"
chr10   1       2       A
chr2    1       2       B
chr1    1       2       C

And the result is:

$ echo -e "chr10\t1\t2\tA\nchr2\t1\t2\tB\nchr1\t1\t2\tC" | sort -k1,1V
chr1    1       2       C
chr2    1       2       B
chr10   1       2       A

Related

Next
Previous
comments powered by Disqus