Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1
tags 18168 notabug
close 18168
stop
(triaging old bugs)
Hello,
It seems your message was lost and not replied to in 4 years.
Sorry about that.
On 2014-08-01 3:38 a.m., Schleusener, Jens wrote:
I am not sure if it's a bug or not but for my application cases the
"sort" command with use of the very helpful option "-V" (natural sort of
(version) numbers within text) not always delivers the by me expected
output.
Example input file (with four test cases):
1.0.5_src.tar.gz
1.0_src.tar.gz
2.0.5src.tar.gz
2.0src.tar.gz
3.0.5/
3.0/
4.0.5beta/
4.0beta/
Sorted ("sort -V") output file (with errors?):
1.0.5_src.tar.gz
1.0_src.tar.gz
2.0src.tar.gz
2.0.5src.tar.gz
3.0.5/
3.0/
4.0beta/
4.0.5beta/
By me expected output file:
1.0_src.tar.gz
1.0.5_src.tar.gz
2.0src.tar.gz
2.0.5src.tar.gz
3.0/
3.0.5/
4.0beta/
4.0.5beta/
The disagreement is about "1.0_src.tar.gz" vs "1.0.5_src.tar.gz"
and "3.0/" vs "3.0.5/" .
Note that these characters are not strictly valid characters in debian
version strings.
Let's try to compare them using Debian's own tools:
First, define a tiny shell function to help compare strings:
compver() {
dpkg --compare-versions "$1" lt "$2" \
&& printf "%s\n" "$1" "$2" \
|| printf "%s\n" "$2" "$1"
}
Then, compare the values:
$ compver 1.0.5_src.tar.gz 1.0_src.tar.gz
dpkg: warning: version '1.0.5_src.tar.gz' has bad syntax: invalid
character in version number
dpkg: warning: version '1.0_src.tar.gz' has bad syntax: invalid
character in version number
dpkg: warning: version '3.0/' has bad syntax: invalid character in
version number
dpkg: warning: version '3.0.5/' has bad syntax: invalid character in
version number
3.0.5/
3.0/
So sort's order agrees with Debian's ordering rules.
It might not be what a "natural sort" algorithm would do, but version-sort
is not exactly natural-sort.
Another detailed example of a version-sort is here: