Numeric sort error
Hello all
I have data like below where the column with values (PRI, SEC ) is the char field and the rest are Numeric Fields.
200707,9580,58,7,2,1,PRI,1,1,137,205594,0,5,10,-45.51,-45.51
200707,9580,58,7,2,1,SEC,1,1,137,205594,0,5,10,-45.51,45.51
200707,9580,58,7,2,1,PRI,1,1,138,204173,0,5,10,-58.51,-58.51
200707,9580,58,7,2,1,SEC,1,1,138,204173,0,5,10,-58.51,58.51
200707,9580,58,7,2,1,PRI,1,1,139,170842,0,5,10,-25.98,-25.98
200707,9580,58,7,2,1,SEC,1,1,139,170842,0,5,10,-25.98,25.98
When i did sort on the above data using the below command:
sort -n -t',' +0 -1 +1 -2 +2 -3 +3 -4 +4 -5 +5 -6 +6 -7 +7 -8 +8 -9 +9 -10 +10 -11
Result is like:
200707,9580,58,7,2,1,PRI,1,1,137,205594,0,5,10,-45.51,-45.51
200707,9580,58,7,2,1,SEC,1,1,137,205594,0,5,10,-45.51,45.51
200707,9580,58,7,2,1,PRI,1,1,138,204173,0,5,10,-58.51,-58.51
200707,9580,58,7,2,1,SEC,1,1,138,204173,0,5,10,-58.51,58.51
200707,9580,58,7,2,1,PRI,1,1,139,170842,0,5,10,-25.98,-25.98
200707,9580,58,7,2,1,SEC,1,1,139,170842,0,5,10,-25.98,25.98
If you check the data, sort is screwed up, 3rd row should come before second and PRI is lesser than SEC.
But when i sort the same data using the below command
sort -t',' +0 -1n +1 -2n +2 -3n +3 -4n +4 -5n +5 -6n +6 -7 +7 -8n +8 -9n +9 -10n
I made each field numeric specfic and PRI, SEC field left as Ascii
I got the below result which the right one
200707,9580,58,7,2,1,PRI,1,1,137,205594,0,5,10,-45.51,-45.51
200707,9580,58,7,2,1,PRI,1,1,138,204173,0,5,10,-58.51,-58.51
200707,9580,58,7,2,1,PRI,1,1,139,170842,0,5,10,-25.98,-25.98
200707,9580,58,7,2,1,SEC,1,1,137,205594,0,5,10,-45.51,45.51
200707,9580,58,7,2,1,SEC,1,1,138,204173,0,5,10,-58.51,58.51
200707,9580,58,7,2,1,SEC,1,1,139,170842,0,5,10,-25.98,25.98
When i am sorting either numeric or ascii, why the PRI, SEC is making a difference?