[Solved] sort on numeric part of field

I have ran into a heavy case of PEBCAK*) and could need some advice on what i do wrong:

OS is Linux (kernel 2.6.35), sort --version reports "8.5" from 2010, shell is ksh.

Originally i had a file with with the following structure:

hdisk1 yyy
hdisk2 yyy
hdisk3 yyy
hdisk4 yyy
hdisk5 yyy
hdisk6 yyy
hdisk7 yyy
hdisk7 yyy
hdisk8 yyy
hdisk9 yyy
hdisk10 yyy
hdisk11 yyy
hdisk12 yyy

I wanted to sort the file descendingly based on the numeric part if field 1, so i used the command:

sort -srn -k1.6,1 <file>

which worked as expected with starting line "hdisk12" and ending line "hdisk1".

Now the file format changed and it looks like this:

xxx hdisk1 yyy
xxx hdisk2 yyy
xxx hdisk3 yyy
xxx hdisk4 yyy
xxx hdisk5 yyy
xxx hdisk6 yyy
xxx hdisk7 yyy
xxx hdisk7 yyy
xxx hdisk8 yyy
xxx hdisk9 yyy
xxx hdisk10 yyy
xxx hdisk11 yyy
xxx hdisk12 yyy

Some fixed-length information at the beginning of each line added. But when i changed the command like below the output was not as expected:

# sort -srn -k2.6,2 <file>
xxx hdisk9 yyy
xxx hdisk8 yyy
xxx hdisk7 yyy
xxx hdisk6 yyy
xxx hdisk5 yyy
xxx hdisk4 yyy
xxx hdisk3 yyy
xxx hdisk2 yyy
xxx hdisk12 yyy
xxx hdisk11 yyy
xxx hdisk10 yyy
xxx hdisk1 yyy

Nothing i have tried so far worked and the according to the man page i *think* it should.

I'd be indebted for any pointers. Thanks.

bakunin
________
*) problem exists between keyboard and chair

From man sort :

KEYDEF is F[.C][OPTS][,F[.C][OPTS]] for start and stop position, where F is a field number and C a character position  in
       the field; both are origin 1, and the stop position defaults to the line's end.  If neither -t nor -b is in effect, char
       acters in a field are counted from the beginning of the preceding whitespace.  OPTS is one or more single-letter ordering
       options  [bdfgiMhnRrV],  which override global ordering options for that key.  If no key is given, use the entire line as
       the key.

So if you change your command to sort -srn -k2.7,2 file , it should do the trick. Or try sort -t' ' -srn -k2.6,2 file .

Oops. *blushes*

You are right, i have found that it works with specifying "-t ' '" already, but was still wondering why. Would i have not only read the man page but also understood what it says i should have known.

Thanks for this.

bakunin