GNU bug report logs - #30661
sort: add sort-by-hex-number feature

Previous Next

Package: coreutils;

Reported by: James Bunke <james_a_bunke <at> yahoo.com>

Date: Thu, 1 Mar 2018 00:02:01 UTC

Severity: wishlist

Full log


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

From: Eric Blake <eblake <at> redhat.com>
To: James Bunke <james_a_bunke <at> yahoo.com>, 30661-done <at> debbugs.gnu.org,
 GNU bug control <control <at> debbugs.gnu.org>
Subject: Re: bug#30661: sort
Date: Thu, 1 Mar 2018 10:15:36 -0600
tag 30661 notabug
thanks

On 02/28/2018 05:42 PM, James Bunke wrote:
> To: bug-coreutils <at> gnu.org
> 
> This seems an oversight than an actual bug:
> 
>      'sort -n' thinks "B" is a larger value than "AA" -- yep! someone
> forgot about hexadecimal, but binary, octal, and decimal work fine.

Please demonstrate an actual command line that you typed and output you 
got.  Here's what I tried in reproducing your claim:

$ printf 'AA\nB\n' | LC_ALL=C sort --debug -n
sort: using simple byte comparison
AA
^ no match for key
__
B
^ no match for key
_

As I typed it, 'sort -n' outputs the line AA before the line B because 
of fallback sorting rules (the entire line is used when none of the keys 
produced a difference, and since neither line was numeric, they were 
equivalently treated as '0' by -n), contrary to your claim that sort 
takes 'B' first.  Therefore, I don't know if my attempt matches what you 
actually saw, as you did not give very many details other than a vague 
verbal description of your issue.

> 
> Suggestion: Don't revert to alphanumeric sorting until the rules are
> broken by the sort field:

Sorry, but 'sort -n' behavior is specified by POSIX, and we can't change 
it, as that would break scripts that expect POSIX behavior.  Most 
likely, sort can already do what you want with additional command line 
options, but I don't even know what data you want sorted, or what output 
you actually want, to tell you what command line would give the output 
you want.  The --debug option can be great at learning what sort is 
actually doing (and how it is more likely that your request is 
incomplete, rather than sort misbehaving).

As such, I'm closing this as not a bug, as you have not demonstrated an 
actual POSIX compliance issue; but do feel free to provide us with more 
information, and we can reopen this if you actually do come up with 
something that needs addressing beyond what sort can already do when 
invoked correctly.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org




This bug report was last modified 6 years and 320 days ago.

Previous Next


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