[Bug 264081] sort -s (i.e., stable sort) does not work correctly

From: <bugzilla-noreply_at_freebsd.org>
Date: Thu, 19 May 2022 15:01:24 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=264081

            Bug ID: 264081
           Summary: sort -s (i.e., stable sort) does not work correctly
           Product: Base System
           Version: 13.1-RELEASE
          Hardware: amd64
                OS: Any
            Status: New
          Severity: Affects Many People
          Priority: ---
         Component: gnu
          Assignee: bugs@FreeBSD.org
          Reporter: kyle@kneisl.org

Created attachment 234035
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=234035&action=edit
chrony "measurements.txt" log output sample

Interestingly, the -s option for sort(1), which is supposed to be a "stable
sort", i.e., preserving the order of items in the original stream when they
have equal sort keys, apparently does not work as intended.  I haven't
exhausted all of the possibilities, but, in my test files over here, it SEEMS
to work for -k1, when the sort key is the first line item.  However, it does
not seem to work in other cases.

I have included a bit of my chronyd measurements log, and you can easily
reproduce.

Note that in the attached file logsample, containing 32 lines in chronological
order for chrony measurements, the following command:

cat logsample | sort -s -k4

produce equally keyed items (in fact, all items have equal keys in the 4th line
item) that are now *NOT* in the same order as the original stream, so that this
sort is NOT stable as expected with -s.  For example:


2022-05-19 13:52:03 192.168.1.197   N  2 111 111 1111   9  9 0.17  2.584e-04 
6.596e-04  3.849e-06  2.155e-02  2.243e-03 98028536 4I D K
2022-05-19 13:43:30 192.168.1.197   N  2 111 111 1111   9  9 0.21  4.559e-04 
5.857e-04  3.849e-06  2.155e-02  1.694e-03 98028536 4I D K
2022-05-19 08:32:09 192.168.1.197   N  2 111 111 1111   9  9 0.30  4.185e-05 
6.944e-04  3.849e-06  2.234e-02  3.952e-03 98028536 4I D K
2022-05-19 08:40:46 192.168.1.197   N  2 111 111 1111   9  9 0.51 -4.130e-05 
5.296e-04  3.849e-06  2.234e-02  4.471e-03 98028536 4I D K

But, 

cat logsample | sort -s -k1

works fine.

I did just upgrade everything to 13.1 yesterday, so I'm not sure how far back
this goes, or if it's new.

-- 
You are receiving this mail because:
You are the assignee for the bug.