• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 271
  • Last Modified:

unexpected sort behaviour

Hi again

I'm having more troubles with the sort command. I tried to sort my data numerically by the first column and then numerically again by the second column

  sort -k1,1n -k2,2n <<END
> 004.1 35
> 004.100 12
> 004.10000 6
> END
004.10000 6
004.100 12
004.1 35


As you can see the first column is not sorted. 004.1 should be before 004.100. The data seems to be in numerical order by the second column. It must be due to the leading zeros as this command works fine on 'normal' numberical data

sort -k1,1n -k2,2n <<END
1 35
100 12
10000 6
1 37

END

1 35
1 37
100 12
10000 6


thanks
0
andieje
Asked:
andieje
  • 2
1 Solution
 
farzanjCommented:
It is doing it correctly.

>> 004.1 should be before 004.100

NO, numerically they are equal so it then sorts by the second column.
0
 
andiejeAuthor Commented:
it isn't working properly - here is another example of the output

004.100   245259  
004.100   245756  
004.1     246576  
004.1     246611  
004.1     246951  
004.1     248137
.004.1     248372  
.004.100   250545

if what you are saying is correct all of the '100s' should be before the '1s'
0
 
andiejeAuthor Commented:
oh sorry i misread what you said. yes you are right
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now