GNU bug report logs - #22455
sort-V not sorting correctly when minor version decimal places differ

Previous Next

Package: coreutils;

Reported by: Vashti <vashtijoy <at> gmail.com>

Date: Sun, 24 Jan 2016 13:28:02 UTC

Severity: normal

Tags: notabug

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 22455 in the body.
You can then email your comments to 22455 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#22455; Package coreutils. (Sun, 24 Jan 2016 13:28:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Vashti <vashtijoy <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Sun, 24 Jan 2016 13:28:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Vashti <vashtijoy <at> gmail.com>
To: bug-coreutils <at> gnu.org
Subject: sort-V not sorting correctly when minor version decimal places differ
Date: Sun, 24 Jan 2016 12:54:57 +0000
[Message part 1 (text/plain, inline)]
Hi, I'm having an issue with a script using coreutils 8.25. Asked to sort
two version numbers, 8.49 and 8.5, it returns them in the wrong order, with
the lowest value second:

$ echo -e '8.49\n8.5' | sort -V
8.5
8.49

I can produce the expected behaviour by correcting the second version
number to two decimal places:

$ echo -e '8.49\n8.50' | sort -V
8.49
8.50

I understand that sort -V is not reliable in all cases, but this seems like
quite a straightforward one.

Thank you.
[Message part 2 (text/html, inline)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#22455; Package coreutils. (Sun, 24 Jan 2016 14:02:01 GMT) Full text and rfc822 format available.

Message #8 received at 22455 <at> debbugs.gnu.org (full text, mbox):

From: Andreas Schwab <schwab <at> linux-m68k.org>
To: Vashti <vashtijoy <at> gmail.com>
Cc: 22455 <at> debbugs.gnu.org
Subject: Re: bug#22455: sort-V not sorting correctly when minor version
 decimal places differ
Date: Sun, 24 Jan 2016 15:01:31 +0100
Vashti <vashtijoy <at> gmail.com> writes:

> Hi, I'm having an issue with a script using coreutils 8.25. Asked to sort
> two version numbers, 8.49 and 8.5, it returns them in the wrong order, with
> the lowest value second:
>
> $ echo -e '8.49\n8.5' | sort -V
> 8.5
> 8.49

5 < 49, so that looks correct.

Andreas.

-- 
Andreas Schwab, schwab <at> linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




Added tag(s) notabug. Request was from Pádraig Brady <P <at> draigBrady.com> to control <at> debbugs.gnu.org. (Sun, 24 Jan 2016 16:43:01 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 22455 <at> debbugs.gnu.org and Vashti <vashtijoy <at> gmail.com> Request was from Pádraig Brady <P <at> draigBrady.com> to control <at> debbugs.gnu.org. (Sun, 24 Jan 2016 16:43:01 GMT) Full text and rfc822 format available.

Information forwarded to bug-coreutils <at> gnu.org:
bug#22455; Package coreutils. (Mon, 25 Jan 2016 02:30:02 GMT) Full text and rfc822 format available.

Message #15 received at 22455 <at> debbugs.gnu.org (full text, mbox):

From: Assaf Gordon <assafgordon <at> gmail.com>
To: Vashti <vashtijoy <at> gmail.com>
Cc: 22455 <at> debbugs.gnu.org
Subject: Re: bug#22455: sort-V not sorting correctly when minor version
 decimal places differ
Date: Sun, 24 Jan 2016 21:29:38 -0500
tag 22455 notabug
close 22455
thanks

Hello,

> On Jan 24, 2016, at 07:54, Vashti <vashtijoy <at> gmail.com> wrote:
> [...]
> I understand that sort -V is not reliable in all cases, but this seems like
> quite a straightforward one.

"sort -V" is reliable (or at least - consistent and well defined in all cases).
It is likely that what you expect a "version string" to be is not how sort treats version strings. 

> $ echo -e '8.49\n8.5' | sort -V
> 8.5
> 8.49
> 
> I can produce the expected behaviour by correcting the second version
> number to two decimal places:
> 
> $ echo -e '8.49\n8.50' | sort -V
> 8.49
> 8.50
> 

First,
In gnu software versions (and in many other places), the number after the decimal point is not the same as a numeric decimal value.
Thus,
version "8.5" is "eight point five",
version "8.50" is "eight point fifty",
version "8.500" is "eight point five-hundred".
These are different versions, and "8.500" is the highest version number among them.

If you need numerical sorting, where "8.5" is equal to "8.50", then "-V" is not the correct sorting option (use "-n" for numeric sort).

Second,
It is incorrect to think of version numbers as decimal-point numbers (in the context of "sort -V").
"sort -V" follows the Debian policy regarding versions ( https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version ) .
Roughly speaking, there are no decimal-point numbers (e.g. "8.5").
Instead, a version string is divided into numeric parts (all digits) and non-numeric parts, and each part is compared separately.

The compared parts are then:
1. "8" vs "8"
2. "." vs "."
3. "5" vs "49"

The first two parts are equal, and in the last part, value "5" comes before "49".
The numeric sort does not care that the non-digit character is a decimal point - it has no special meaning.
Just as well, it might have been a word:

   $ printf "8.49\n8.5\n" | sort -V
   8.5
   8.49

   $ printf "8foo49\n8foo5\n" | sort -V
   8foo5
   8foo49

As such, I'm making this bug as closed, but discussion can continue by replying to this thread.

regards,
 - assaf
 






bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 22 Feb 2016 12:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 8 years and 65 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.