bash - Sort a file to put 10, 11, 12... before 1, 2, 3... and X,Y -


i have list of chromosome data columns (chromosome, start, , end) this:

chr1    6252071 6253740 chr1    6965107 6966070 chr1    6966038 6967016 chr1    7066595 7068694 chr1    7100956 7102296 chr1    7153422 7154635 chr1    7155112 7156181 .... chr2 .... chr10 .... chrx .... chry .... 

etc.

i trying use bash sort chromosome sections order:

chr10 chr11 chr12 chr13 chr14 chr15 chr16 chr17 chr18 chr19 chr1 chr2 chr3 chr4 chr5 chr6 chr7 chr8 chr9 chrm chrx chry 

in first column, , in numerical order start position in second column, no variation of sort seems job. ideas? thanks.

split file 2 streams separate filtering, recombine them:

cat <(grep    '^chr1[[:digit:]][[:space:]]' <inputfile | sort) \     <(grep -v '^chr1[[:digit:]][[:space:]]' <inputfile | sort) \     >outputfile 

Comments