Subject: bin/25551: sort - doesn't sort reverse numeric keys correctly
To: None <gnats-bugs@gnats.NetBSD.org>
From: None <mlh@goathill.org>
List: netbsd-bugs
Date: 05/12/2004 16:36:48
>Number:         25551
>Category:       bin
>Synopsis:       sort - doesn't sort reverse numeric keys correctly
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed May 12 21:37:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     MLH
>Release:        NetBSD 2.0E
>Organization:
none
	
>Environment:
	
	
System: NetBSD enki.goathill.org 2.0E NetBSD 2.0E (GENERIC.MP) #0: Thu May 6 16:36:24 CDT 2004 build@enki.goathill.org:/opt/obj/i386/opt/src/sys/arch/i386/compile/GENERIC.MP i386
Architecture: i386
Machine: i386
>Description:
	
Reverse numeric sorts don't appear to handle empty strings consistently. 
The first key appears correct but subsequent keys don't.

I can't determine that changing the weighting table can fix this and
I can't determine what the difference is between how the first key
is handled and the second key. I would appreciate some assistance with
fixing this.

>How-To-Repeat:
$ cat testsort
         
      0.0
      1.0
  0.0
  0.0 0.0
  0.0 1.0
  1.0
  1.0 0.0
  1.0 1.0
------------------------
Forward numeric (and nonnumeric) 2nd keys sort correctly:
$ sort -t: -k1.6n,1.9 -k1.1n,1.5 testsort
         
  0.0
  1.0
      0.0
  0.0 0.0
  1.0 0.0
      1.0
  0.0 1.0
  1.0 1.0
$ sort -t: -k1.6n,1.9 -k1.1,1.5 testsort
         
  0.0
  1.0
      0.0
  0.0 0.0
  1.0 0.0
      1.0
  0.0 1.0
  1.0 1.0
-------------------------
Reverse numeric first key sorts correctly but not second key:
$ sort -t: -k1.6rn,1.9 -k1.1r,1.5 testsort
  1.0 1.0
  0.0 1.0
      1.0
  1.0 0.0
  0.0 0.0
      0.0
  1.0
  0.0

-------------------------
Reverse numeric first key and reverse nonnumeric second key sorts correctly :
$ sort -t: -k1.6rn,1.9 -k1.1,1.5 testsort
      1.0
  0.0 1.0
  1.0 1.0
      0.0
  0.0 0.0
  1.0 0.0
         
  0.0
  1.0

>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: