Creative Commons License
This blog by Tommy Tang is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

My github papge

Tuesday, September 17, 2013

Amazing GNU sort

I just came across this on Biostar:

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

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

1 comment:

  1. repliche mont blanc Meisterstück, das eleganten Stil und modernste Technologie kombiniert, eine Vielzahl von Stilen von repliche mont blanc fineliner, der Zeiger bewegt sich zwischen Ihrem exklusiven Geschmacksstil.