sort first two fields in numeric order
Robert Felps
felps at convex.com
Wed Jun 19 21:49:37 AEST 1991
In <1991Jun18.222520.7816 at drd.com> mark at drd.com (Mark Lawrence) writes:
>I've got a file with tab separated columns of stuff that I
>expand to pretty tabstops and sort. I want to sort the file
>primarily on the first column and then on the second, both
>numerically. No problem, right?
>expand -5 foo | sort +0n -1n
>should treat both the first and second columns as numerics
>and sort them in that order. It don't. I get:
>16 0
>16 1
>16 10
>16 19
>16 2
>16 21
>I'm missing something terribly obvious here. Comments?
Well, obvious, probably not terribly though. Try,
expand -5 foo | sort +0n +1n
or
expand -5 foo | sort +0n -1n +1n -2n
>From the sort man page:
The notation +pos1 -pos2 restricts a sort key to a field
beginning at pos1 and ending just before pos2.
^^^^^^^^^^^^^^^^^^^^^^^
The +Col +Col format, as in example 1, doesn't provide an ending
column because it is not necessary. As the SYNOPSIS line shows
if pos1 is specified pos2 is optional.
sort [ -mubdfinrctx ] [ +pos1 [ -pos2 ] ] ... [ -o name ]
[ -T directory ] [ name ] ...
>--
>mark at drd.com
>mark at jnoc.go.jp $B!J%^!<%/!&%i%l%s%9!K(B Nihil novum sub solem
Hope this helps,
Robert Felps I do not speak for felps at convex.com
Convex Computer Corp Convex and I seldom Product Specialist
3000 Waterview Parkway speak for myself. Tech. Assistant Ctr
Richardson, Tx. 75080 VMS? What's that? 1(800) 952-0379
More information about the Comp.unix.questions
mailing list