* Sort keys buggy?
@ 1996-02-28 5:00 Michael P Urban
1996-02-29 5:00 ` Mike Stroyan
0 siblings, 1 reply; 2+ messages in thread
From: Michael P Urban @ 1996-02-28 5:00 UTC (permalink / raw)
The output of the command,
sort -k 1 -k 2n
with an input file like:
a 1
a 3
a 4
b 1
b 2
b 3
x 4
y 2
a 10
a 50
b 10
b 20
b 50
z 20
a 25
b 25
does not produce the result I would expect; the second column is
sorted lexicographically instead of numerically. This occurs on HP-UX
9.01, HP-UX 10, and DEC OSF1 V3.2.
Am I misunderstanding the usage of the -k options, or are the DEC and
HP programmers?
Mike Urban
urban@cobra.jpl.nasa.gov
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Sort keys buggy?
1996-02-28 5:00 Sort keys buggy? Michael P Urban
@ 1996-02-29 5:00 ` Mike Stroyan
0 siblings, 0 replies; 2+ messages in thread
From: Mike Stroyan @ 1996-02-29 5:00 UTC (permalink / raw)
Michael P Urban (urban@cobra.jpl.nasa.gov) wrote:
|The output of the command,
| sort -k 1 -k 2n
|with an input file like:
...
|b 2
...
|b 10
|b 20
...
|does not produce the result I would expect; the second column is
|sorted lexicographically instead of numerically. This occurs on HP-UX
|9.01, HP-UX 10, and DEC OSF1 V3.2.
The trick is that the first key, "-k 1", is specifying a range from
the start of the first field to the end of line. All of the lines are
unique in that key, so the second key never gets a chance to influence
the sort.
You can get the effect you were looking for by using a first key that
is only the first field-
sort -k 1,1 -k 2n
--
Mike Stroyan, mike_stroyan@fc.hp.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1996-02-29 5:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-02-28 5:00 Sort keys buggy? Michael P Urban
1996-02-29 5:00 ` Mike Stroyan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox