GNU bug report logs - #9334
sort bug

Previous Next

Package: coreutils;

Reported by: "ROGER GRAYDON CHRISTMAN" <dvl <at> psu.edu>

Date: Sat, 20 Aug 2011 20:28:01 UTC

Severity: normal

Done: Bob Proulx <bob <at> proulx.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: "ROGER GRAYDON CHRISTMAN" <dvl <at> psu.edu>
Subject: bug#9334: closed (Re: bug#9334: sort bug)
Date: Mon, 22 Aug 2011 01:59:01 +0000
[Message part 1 (text/plain, inline)]
Your bug report

#9334: sort bug

which was filed against the coreutils package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to 9334 <at> debbugs.gnu.org.

-- 
9334: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=9334
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Bob Proulx <bob <at> proulx.com>
To: ROGER GRAYDON CHRISTMAN <dvl <at> psu.edu>
Cc: 9334-done <at> debbugs.gnu.org
Subject: Re: bug#9334: sort bug
Date: Sun, 21 Aug 2011 19:55:57 -0600
tags 9334 + notabug
thanks

ROGER GRAYDON CHRISTMAN wrote:
> First: some version information:
> sort (GNU coreutils) 8.4

Thanks!

> I run a series of pipes, and after piping into 'sort -n', I see this: 
>     1   12
>     1    4
>     5   16
>     9   20
> 
> The first column sorted correctly, numerically, but the second did not.
> I do not have sufficient data to determine whether the second column
> is sorted lexicographically, or simply ignored.

Thanks for the report but you are not seeing a bug in sort but in the
use of it.  You have insufficiently qualified the sort criteria.  Try
this:

  sort -n -k1,1 -k2,2

Or my preference:

  sort -k1,1n -k2,2n

The reasoning is as found in the sort documentation:

     A pair of lines is compared as follows: `sort' compares each pair of
  fields, in the order specified on the command line, according to the
  associated ordering options, until a difference is found or no fields
  are left.  If no key fields are specified, `sort' uses a default key of
  the entire line.  Finally, as a last resort when all keys compare
  equal, `sort' compares entire lines as if no ordering options other
  than `--reverse' (`-r') were specified.  The `--stable' (`-s') option
  disables this "last-resort comparison" so that lines in which all
  fields compare equal are left in their original relative order.  The
  `--unique' (`-u') option also disables the last-resort comparison.
  ...
  `-n'
  `--numeric-sort'
  `--sort=numeric'
       Sort numerically.  The number begins each line and consists of
       optional blanks, an optional `-' sign, and zero or more digits
       possibly separated by thousands separators, optionally followed by
       a decimal-point character and zero or more digits.  An empty
       number is treated as `0'.  ...

Since no fields are specified sort is using a default key of the
entire line.  Since you care about sorting on fields you should
include sort field options.

Bob

[Message part 3 (message/rfc822, inline)]
From: "ROGER GRAYDON CHRISTMAN" <dvl <at> psu.edu>
To: bug-coreutils <at> gnu.org
Subject: sort bug
Date: Sat, 20 Aug 2011 10:54:45 -0400
[Message part 4 (text/plain, inline)]
First: some version information:
sort (GNU coreutils) 8.4

I run a series of pipes, and after piping into 'sort -n', I see this: 
    1   12
    1    4
    5   16
    9   20

The first column sorted correctly, numerically, but the second did not.
I do not have sufficient data to determine whether the second column
is sorted lexicographically, or simply ignored.

Roger Christman
Computer Science and Engineering
Pennsylvania State Univeristy





[Message part 5 (text/html, inline)]

This bug report was last modified 13 years and 275 days ago.

Previous Next


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