bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#58153: hungry sort eats lines


From: Pádraig Brady
Subject: bug#58153: hungry sort eats lines
Date: Wed, 28 Sep 2022 23:36:42 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:98.0) Gecko/20100101 Thunderbird/98.0

On 28/09/2022 22:13, DrSlony wrote:
Hey

printf '%s\n' "key;foo" "key0;bar0" | sort -Vu -t ';' --key=1,1

sort 8.32 outputs:
      key;bar
      key0;foo

sort 9.1 outputs:
      key;foo

"key0;foo" is missing.

You're using version sort and '0' is special to version sorting.
Specifically as per 
https://www.debian.org/doc/debian-policy/ch-controlfields.html#version
In particular this portion of the documented comparison algorithm:

"Then the initial part of the remainder of each string which consists entirely
 of digit characters is determined. The numerical values of these two parts are 
compared,
  and any difference found is returned as the result of the comparison.
  For these purposes an empty string (which can only occur at the end of one or 
both
  version strings being compared) counts as zero."

You can see this in the simplified example:

# Use --check to see if any matches that need to be dropped:
$ printf '%s\n' "key" "key0" | sort -u -C -V || echo equal
equal

# Here 1 is treated differently:
$ printf '%s\n' "key" "key1" | sort -u -c -V && echo different
different

I agree this is surprising, but version sorting has lots of edge cases,
so it's probably best to stick to the documented algorithm here.

thanks,
Pádraig





reply via email to

[Prev in Thread] Current Thread [Next in Thread]