/bin/sort bug - (nf)

johnl at ima.UUCP johnl at ima.UUCP
Thu Sep 1 08:40:37 AEST 1983


#R:ccieng5:-13300:ima:35700002:000:815
ima!johnl    Aug 31 18:02:00 1983

    I don't think that /bin/sort works right.  ... The bottom line is
    that sort continues to look at the remaining fields in the line even
    though the "-pos" argument tells him not to.

The sort page in my Unix manual says:

    When there are multiple sort keys, later keys are compared only after
    all earlier keys compare equal.   Lines that otherwise compare equal
    are ordered with all bytes significant.

so sort behaves exactly the way the documentation says it does.  I think
this language in the manual page dates back at least to V7.  If you want
a stable sort, you can number the lines, sort, and un-number them.  On
S/3, you could say:

	pr -t -n file | sort +1 -2 +0n | sed "s/^.....//"

to do that.  A "stable" option to sort would have to do the same internally.

John Levine, ima!johnl



More information about the Comp.unix.wizards mailing list