sort -n with more than one column

sort -n with more than one column

I'd like to sort a file with 9 integer values per line according
to the values of the first three "columns" and in the natural integer order.
The result would look like

-4 -4 -4 .....
...
-4 -4 -3 .....

-3 -4 -4 ....

Using
sort -k 1n,3n ....
or
sort -n 1,3
sorts only the first column (first integer) correctly in the order
from -5,-4,-3,-2,-1,0,1,2..., but the 2nd and 3rd column in the order
-1,-2,-3,-4,...0,1,2,3 (mixes up the ordering for the 2nd and 3rd column).
We're using /usr/bin/sort  in the version of
98 1.60 src/bos/usr/bin/sort/sort.c, cmdfiles, bos41c, 9536A 9/1/95
under AIX 1 4 000033727900. Is there a trick to achieve ordering
with the natural order for integers for all columns of the input?
--

sort -n with more than one column

>I'd like to sort a file with 9 integer values per line according
>to the values of the first three "columns" and in the natural integer order.
>The result would look like
>-4 -4 -4 .....
>...
>-4 -4 -3 .....
>-3 -4 -4 ....
>Using
>   sort -k 1n,3n ....
>or
>   sort -n 1,3
>sorts only the first column (first integer) correctly in the order
>from -5,-4,-3,-2,-1,0,1,2..., but the 2nd and 3rd column in the order
> -1,-2,-3,-4,...0,1,2,3 (mixes up the ordering for the 2nd and 3rd column).
>We're using /usr/bin/sort  in the version of
> 98 1.60 src/bos/usr/bin/sort/sort.c, cmdfiles, bos41c, 9536A 9/1/95
>under AIX 1 4 000033727900. Is there a trick to achieve ordering
>with the natural order for integers for all columns of the input?
>--

Hi.

Use

sort -n +0 -n +1 -n +2 file

Have fun,

Fred
--
Fred Hucht, Institute of Theoretical Physics, University of Duisburg, Germany

"Der Koerper der algebraischen Zahlen ist kein algebraischer Zahlkoerper"
(E. Landau, Zahlentheorie (1927), Satz 718)

sort -n with more than one column

: I'd like to sort a file with 9 integer values per line according
: to the values of the first three "columns" and in the natural integer order.
: The result would look like

: -4 -4 -4 .....
: ...
: -4 -4 -3 .....

: -3 -4 -4 ....

: Using
:    sort -k 1n,3n ....
: or
:    sort -n 1,3
: sorts only the first column (first integer) correctly in the order
: from -5,-4,-3,-2,-1,0,1,2..., but the 2nd and 3rd column in the order
:  -1,-2,-3,-4,...0,1,2,3 (mixes up the ordering for the 2nd and 3rd column).
: We're using /usr/bin/sort  in the version of
:  98 1.60 src/bos/usr/bin/sort/sort.c, cmdfiles, bos41c, 9536A 9/1/95
: under AIX 1 4 000033727900. Is there a trick to achieve ordering
: with the natural order for integers for all columns of the input?
: --

You  have to explicitly sort on each column:

sort -kn1.1,1 -kn2.1,2 -kn3.1,3

...Tom
----------------------------------------------------------------------------
Tom Fleck                                                   OC Systems, Inc.
Senior Software Engineer                      Ada Systems Software and Tools

(703)359-8168 - Voice                                    FAX - (703)359-8161

I need to sort data by the second column while keeping
the first column unique. There is probably an easy way to
do this that I'm totally missing.
The first column is an inmate number. The second column
is the bond amount. I'm going to output the criminals based
on the bond amount, with the highest bonds at the top.
My problem is that if someone has two bond amounts, that
person makes the list twice. I only one folks listed based on
the highest individual bond amount. (A guy with a \$10k bond
should be before someone with three \$5k bonds.)

Unsorted                          What I Want
98051461~250.00                   98051385~5000.00
98051461~0.00                     98051487~750.00
98051403~500.00                   98051403~500.00
98051487~750.00                   98051461~250.00
98051487~750.00
98051385~1500.00
98051385~1500.00
98051385~0.00
98051385~0.00
98051385~5000.00

I'm using... sort -rnt "~" -k 2 \$INPUT | uniq ...which
solves the problem when someone has multiple bonds of the
same amount but doesn't help when the bonds are varying.
A perl solution would be a wonderful thing but I'm currently
getting the data externally (open DINNER, "sort -rnt \"~\" -k 2
\$Temp | uniq |" or die "Can't fork: \$!" ;) so I'll take any
solution that works. (Yes, the above is cheezy.)
All suggestions (and requisite mocking) welcome.
Many thanks.

Matt