Sorting tab delimited text file based on multiple columns in natural way [duplicate]
- by Vignesh
This question already has an answer here:
Sorting a column of CSV file resulting in 1123 appearing before 232
1 answer
I am trying to sort a file based on all two columns
Eg:
chr19 1070019 1070020
chr16 869712 869713
chr1 1378131 1378132
chr12 189386 189387
chr4 254941 254942
chr16 1476500 1476501
chr2 1476810 1476811
chr19 313283 313284
chr17 595817 595818
chr18 656897 656898
chr19 1061829 1061830
I Tried sort -t $\t -k1,1 2,2 <filename> but doesn't work.
I want the output to be sorted by first column and second column based on first column.
I want to do a natural sort. Not lexical sorting.
Eg:
chr1 1378131 1378132
chr2 1476810 1476811
chr4 254941 254942
chr12 189386 189387
chr16 869712 869713
chr16 1476500 1476501
chr17 595817 595818
chr18 656897 656898
chr19 313283 313284
chr19 1061829 1061830
chr19 1070019 1070020
Anyone any idea?