You are not logged in.

#1 2011-08-08 07:44:10

nsb
Member
From: Switzerland
Registered: 2008-03-26
Posts: 57

[solved] sort first according to first, then second column

Hey

I am having a little prolem with sort. I want to sort a file like that:

   1  10   0
   1  10   0
   1 100   0
   1 100   5
   1 101   0
   1 101   2
   1 102   0
   1 102   0
   1 103   0
   2 103   0
   1 104   0
   1  11   0
   1  11   0
   1  12   0
   1  12   0

so it would look like that:

   1  10   0
   1  10   0
   1  11   0
   1  11   0
   1  12   0
   1  12   0
   1 100   0
   1 100   5
   1 101   0
   1 101   2
   1 102   0
   1 102   0
   1 103   0
   1 104   0
   2 103   0

But, when I sort it with

sort -k 1n,2n file

or

sort -g -k 1,2 file

I always get

   1  10   0
   1  10   0
   1 100   0
   1 100   5
   1 101   0
   1 101   2
   1 102   0
   1 102   0
   1 103   0
   1 104   0
   1  11   0
   1  11   0
   1  12   0
   1  12   0
   2 103   0

Is there a simple solution?

Regards
nsb

Last edited by nsb (2011-08-08 09:57:49)

Offline

#2 2011-08-08 09:34:16

lula
Member
Registered: 2009-07-16
Posts: 71

Re: [solved] sort first according to first, then second column

I think the right options should be

 sort  -k1,1n -k2,2n file

You can use the --debug option of sort to see what's happening.

Offline

#3 2011-08-08 09:57:33

nsb
Member
From: Switzerland
Registered: 2008-03-26
Posts: 57

Re: [solved] sort first according to first, then second column

Thank you! That worked!

nsb

Offline

Board footer

Powered by FluxBB