From unknown Fri Jun 20 07:09:29 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#9334 <9334@debbugs.gnu.org> To: bug#9334 <9334@debbugs.gnu.org> Subject: Status: sort bug Reply-To: bug#9334 <9334@debbugs.gnu.org> Date: Fri, 20 Jun 2025 14:09:29 +0000 retitle 9334 sort bug reassign 9334 coreutils submitter 9334 "ROGER GRAYDON CHRISTMAN" severity 9334 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Sat Aug 20 16:27:50 2011 Received: (at submit) by debbugs.gnu.org; 20 Aug 2011 20:27:50 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Qus8z-0003sY-8H for submit@debbugs.gnu.org; Sat, 20 Aug 2011 16:27:50 -0400 Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QurtP-0002rO-F8 for submit@debbugs.gnu.org; Sat, 20 Aug 2011 16:11:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QurrG-0001XE-9E for submit@debbugs.gnu.org; Sat, 20 Aug 2011 16:09:31 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,HTML_MESSAGE, RCVD_IN_DNSWL_LOW, RECEIVED_FROM_WINDOWS_HOST, RP_MATCHES_RCVD autolearn=no version=3.3.1 Received: from lists.gnu.org ([140.186.70.17]:47469) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QurrG-0001XA-7n for submit@debbugs.gnu.org; Sat, 20 Aug 2011 16:09:30 -0400 Received: from eggs.gnu.org ([140.186.70.92]:39081) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QurrF-0008TL-CW for bug-coreutils@gnu.org; Sat, 20 Aug 2011 16:09:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QurrE-0001Wu-Io for bug-coreutils@gnu.org; Sat, 20 Aug 2011 16:09:29 -0400 Received: from tr21g10.aset.psu.edu ([146.186.149.132]:45589) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QurrE-0001We-F0 for bug-coreutils@gnu.org; Sat, 20 Aug 2011 16:09:28 -0400 Received: from tr22n03.aset.psu.edu (tr22g03.aset.psu.edu [146.186.16.13]) by tr21g10.aset.psu.edu (8.14.3/8.14.3) with ESMTP id p7KEsjkF2756756 for ; Sat, 20 Aug 2011 10:54:45 -0400 Received: (from dvl@localhost) by tr22n03.aset.psu.edu (8.14.1/8.14.1) id p7KEsjlr868394; Sat, 20 Aug 2011 10:54:45 -0400 Date: Sat, 20 Aug 2011 10:54:45 -0400 To: bug-coreutils@gnu.org From: "ROGER GRAYDON CHRISTMAN" Subject: sort bug X-Mailer: Penn State WebMail 2.3.0 X-Sender: dvl X-Originating-IP: 130.203.102.55 Message-Id: <1313852084l.602232l.0l@psu.edu> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="=-3IP2HjEsRTfHa/sroDSy" X-Virus-Scanned: by amavisd-new X-detected-operating-system: by eggs.gnu.org: Windows 98 (no sack) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.17 X-Spam-Score: -6.6 (------) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Sat, 20 Aug 2011 16:27:48 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -6.6 (------) --=-3IP2HjEsRTfHa/sroDSy Content-Type: text/plain; charset=utf-8 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 --=-3IP2HjEsRTfHa/sroDSy Content-Type: text/html; charset=utf-8 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





--=-3IP2HjEsRTfHa/sroDSy-- From debbugs-submit-bounces@debbugs.gnu.org Sun Aug 21 21:58:22 2011 Received: (at 9334-done) by debbugs.gnu.org; 22 Aug 2011 01:58:22 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QvJmO-0004gU-SH for submit@debbugs.gnu.org; Sun, 21 Aug 2011 21:58:21 -0400 Received: from joseki.proulx.com ([216.17.153.58]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QvJmL-0004gL-Q2 for 9334-done@debbugs.gnu.org; Sun, 21 Aug 2011 21:58:19 -0400 Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119]) by joseki.proulx.com (Postfix) with ESMTP id EE39621312; Sun, 21 Aug 2011 19:55:57 -0600 (MDT) Received: by hysteria.proulx.com (Postfix, from userid 1000) id A8A572DC83; Sun, 21 Aug 2011 19:55:57 -0600 (MDT) Date: Sun, 21 Aug 2011 19:55:57 -0600 From: Bob Proulx To: ROGER GRAYDON CHRISTMAN Subject: Re: bug#9334: sort bug Message-ID: <20110822015557.GB7161@hysteria.proulx.com> References: <1313852084l.602232l.0l@psu.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1313852084l.602232l.0l@psu.edu> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Score: -2.5 (--) X-Debbugs-Envelope-To: 9334-done Cc: 9334-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.5 (--) 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 From debbugs-submit-bounces@debbugs.gnu.org Mon Aug 22 00:13:34 2011 Received: (at 9334) by debbugs.gnu.org; 22 Aug 2011 04:13:34 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QvLtG-0005LT-Gv for submit@debbugs.gnu.org; Mon, 22 Aug 2011 00:13:34 -0400 Received: from mail-vx0-f172.google.com ([209.85.220.172]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QvLtE-0005LM-A8 for 9334@debbugs.gnu.org; Mon, 22 Aug 2011 00:13:33 -0400 Received: by vxi29 with SMTP id 29so3809048vxi.3 for <9334@debbugs.gnu.org>; Sun, 21 Aug 2011 21:11:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=UIQyqGDNgtRrN3+VJDbeOCqKHZvkEOROVNx2MgNUPBA=; b=h9zeABqe9dUuGb2TyuTcqh48OTHvK7WIjGT4X/M1/fxV069ercuKzmyXIKBe34ainX yhBdmSlZ87fROWM499XNbUi9tZ/5OTJ3qxS6nm4rFZdMPWcHDTvGfNyOJZDYlMur2J45 CMuqL/992TWYIBFkCN1b8TDYrUk4RcvFK8g0o= MIME-Version: 1.0 Received: by 10.52.111.10 with SMTP id ie10mr1294023vdb.237.1313986272042; Sun, 21 Aug 2011 21:11:12 -0700 (PDT) Received: by 10.220.98.139 with HTTP; Sun, 21 Aug 2011 21:11:12 -0700 (PDT) In-Reply-To: <20110822015557.GB7161@hysteria.proulx.com> References: <1313852084l.602232l.0l@psu.edu> <20110822015557.GB7161@hysteria.proulx.com> Date: Mon, 22 Aug 2011 00:11:12 -0400 Message-ID: Subject: Re: bug#9334: sort bug From: Aaron Davies To: "9334@debbugs.gnu.org" <9334@debbugs.gnu.org>, "bob@proulx.com" Content-Type: multipart/alternative; boundary=bcaec548a40dfc1e5b04ab1044aa X-Spam-Score: -3.6 (---) X-Debbugs-Envelope-To: 9334 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -3.6 (---) --bcaec548a40dfc1e5b04ab1044aa Content-Type: text/plain; charset=ISO-8859-1 On Sunday, August 21, 2011, Bob Proulx wrote: > 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. Out of curiosity, what's the output mean in this case? "two lines, starting with the number one, in their original order", "two lines, starting with the number one, also containing the strings '12' and '4' and sorted lexicographically thereby", or something else entirely? -- Aaron Davies aaron.davies@gmail.com --bcaec548a40dfc1e5b04ab1044aa Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Sunday, August 21, 2011, Bob Proulx <bob@proulx.com> wrote:
> tags 9334 + notabug
> thanks<= br>>
> ROGER GRAYDON CHRISTMAN wrote:
>> First: some vers= ion information:
>> sort (GNU coreutils) 8.4
>
> Thanks!
>
>&g= t; I run a series of pipes, and after piping into 'sort -n', I see = this:
>> =A0 =A0 1 =A0 12
>> =A0 =A0 1 =A0 =A04
>&g= t; =A0 =A0 5 =A0 16
>> =A0 =A0 9 =A0 20
>>
>> The first column sorted c= orrectly, numerically, but the second did not.
>> I do not have su= fficient 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. =A0You have insufficiently qualified the sort cr= iteria. =A0Try
> this:
>
> =A0sort -n -k1,1 -k2,2
>=
> Or my preference:
>
> =A0sort -k1,1n -k2,2n
>
>= ; The reasoning is as found in the sort documentation:
>
> =A0 = =A0 A pair of lines is compared as follows: `sort' compares each pair o= f
> =A0fields, in the order specified on the command line, according to th= e
> =A0associated ordering options, until a difference is found or no= fields
> =A0are left. =A0If no key fields are specified, `sort' = uses a default key of
> =A0the entire line. =A0Finally, as a last resort when all keys compare=
> =A0equal, `sort' compares entire lines as if no ordering optio= ns other
> =A0than `--reverse' (`-r') were specified. =A0The = `--stable' (`-s') option
> =A0disables this "last-resort comparison" so that lines in w= hich all
> =A0fields compare equal are left in their original relativ= e order. =A0The
> =A0`--unique' (`-u') option also disables t= he last-resort comparison.
> =A0...
> =A0`-n'
> =A0`--numeric-sort'
> =A0= `--sort=3Dnumeric'
> =A0 =A0 =A0 Sort numerically. =A0The number = begins each line and consists of
> =A0 =A0 =A0 optional blanks, an op= tional `-' sign, and zero or more digits
> =A0 =A0 =A0 possibly separated by thousands separators, optionally fol= lowed by
> =A0 =A0 =A0 a decimal-point character and zero or more dig= its. =A0An empty
> =A0 =A0 =A0 number is treated as `0'. =A0...>
> Since no fields are specified sort is using a default key of= the
> entire line. =A0Since you care about sorting on fields you should
&= gt; include sort field options.

Out of curiosity, what's the out= put mean in this case? "two lines, starting with the number one, in th= eir original order", "two lines, starting with the number one, al= so containing the strings '12' and '4' and sorted lexicogra= phically thereby", or something else entirely?

--
Aaron Davies
aaron.= davies@gmail.com
--bcaec548a40dfc1e5b04ab1044aa-- From debbugs-submit-bounces@debbugs.gnu.org Mon Aug 22 10:42:07 2011 Received: (at 9334) by debbugs.gnu.org; 22 Aug 2011 14:42:07 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QvVhW-0005gp-AW for submit@debbugs.gnu.org; Mon, 22 Aug 2011 10:42:06 -0400 Received: from joseki.proulx.com ([216.17.153.58]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QvVhP-0005gN-TV for 9334@debbugs.gnu.org; Mon, 22 Aug 2011 10:42:01 -0400 Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119]) by joseki.proulx.com (Postfix) with ESMTP id DEEF72130F for <9334@debbugs.gnu.org>; Mon, 22 Aug 2011 08:39:36 -0600 (MDT) Received: by hysteria.proulx.com (Postfix, from userid 1000) id 82BD42DC7F; Mon, 22 Aug 2011 08:39:36 -0600 (MDT) Resent-From: Bob Proulx Resent-Date: Mon, 22 Aug 2011 08:39:36 -0600 Resent-Message-ID: <20110822143936.GA13343@hysteria.proulx.com> Resent-To: 9334@debbugs.gnu.org X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on hysteria.proulx.com X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00,HTML_MESSAGE, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-Original-To: bob@hysteria.proulx.com Received: from joseki.proulx.com (joseki.proulx.com [192.168.230.3]) by hysteria.proulx.com (Postfix) with ESMTP id 5C4882DC7B for ; Mon, 22 Aug 2011 07:47:17 -0600 (MDT) Received: by joseki.proulx.com (Postfix, from userid 1000) id 59A7021419; Mon, 22 Aug 2011 07:47:17 -0600 (MDT) X-Original-To: bob@proulx.com X-External-Mail: yes Received-SPF: none (psu.edu: No applicable sender policy available) receiver=joseki.proulx.com; identity=mfrom; envelope-from="dvl@psu.edu"; helo=tr21g10.aset.psu.edu; client-ip=146.186.149.132 Received: from tr21g10.aset.psu.edu (tr21g10.aset.psu.edu [146.186.149.132]) by joseki.proulx.com (Postfix) with ESMTP id 08A212130F for ; Mon, 22 Aug 2011 07:47:16 -0600 (MDT) Received: from tr22n03.aset.psu.edu (tr22g03.aset.psu.edu [146.186.16.13]) by tr21g10.aset.psu.edu (8.14.3/8.14.3) with ESMTP id p7MDlD2S2732164 for ; Mon, 22 Aug 2011 09:47:14 -0400 Received: (from dvl@localhost) by tr22n03.aset.psu.edu (8.14.1/8.14.1) id p7MDlDof372932; Mon, 22 Aug 2011 09:47:13 -0400 Date: Mon, 22 Aug 2011 09:47:13 -0400 To: Bob Proulx From: "ROGER GRAYDON CHRISTMAN" Subject: Re: bug#9334: sort bug X-Mailer: Penn State WebMail 2.3.0 X-Sender: dvl X-Originating-IP: 130.203.102.65 In-Reply-To: 20110822015557.GB7161@hysteria.proulx.com References: <1313852084l.602232l.0l@psu.edu><20110822015557.GB7161@hysteria.proulx.com> Message-Id: <1314020833l.1261732l.0l@psu.edu> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="=-GDGqH0kz0tcEshWsKWQC" X-Virus-Scanned: by amavisd-new X-Spam-Score: -4.6 (----) X-Debbugs-Envelope-To: 9334 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org Resent-Date: Mon, 22 Aug 2011 10:42:06 -0400 X-Spam-Score: -3.9 (---) --=-GDGqH0kz0tcEshWsKWQC Content-Type: text/plain; charset=utf-8 Thanks. I guess I misinterpreted "uses a default key of the entire line" as "uses the entire line as keys by default", in which case if the first column was equal, it would compare the second, then the third, etc. I guess I don't know what "default key of the entire line" means with respect to -n, since it apparently didn't treat "1 12" as "112" and "1 4" as 14. I'm curious to find out what this phrase means in this context. Roger Christman On Sun, Aug 21, 2011 09:55 PM, Bob Proulx wrote: > 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 > > > --=-GDGqH0kz0tcEshWsKWQC Content-Type: text/html; charset=utf-8
Thanks.  I guess I misinterpreted "uses a default key of the entire line"
as "uses the entire line as keys by default", in which case if the first column
was equal, it would compare the second, then the third, etc.

I guess I don't know what "default key of the entire line" means with respect to -n,
since it apparently didn't treat "1    12" as "112" and "1   4" as 14.
I'm curious to find out what this phrase means in this context.

Roger Christman

On Sun, Aug 21, 2011 09:55 PM, Bob Proulx <bob@proulx.com> wrote:
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


--=-GDGqH0kz0tcEshWsKWQC-- From debbugs-submit-bounces@debbugs.gnu.org Mon Aug 22 10:47:25 2011 Received: (at 9334) by debbugs.gnu.org; 22 Aug 2011 14:47:25 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QvVme-0006U0-Jb for submit@debbugs.gnu.org; Mon, 22 Aug 2011 10:47:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QvVmb-0006Ts-84 for 9334@debbugs.gnu.org; Mon, 22 Aug 2011 10:47:22 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p7MEiwXG027202 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 22 Aug 2011 10:44:58 -0400 Received: from [10.3.113.118] (ovpn-113-118.phx2.redhat.com [10.3.113.118]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p7MEivm5002292; Mon, 22 Aug 2011 10:44:57 -0400 Message-ID: <4E526B69.7060108@redhat.com> Date: Mon, 22 Aug 2011 08:44:57 -0600 From: Eric Blake Organization: Red Hat User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110621 Fedora/3.1.11-1.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.11 MIME-Version: 1.0 To: ROGER GRAYDON CHRISTMAN Subject: Re: bug#9334: sort bug References: <1313852084l.602232l.0l@psu.edu><20110822015557.GB7161@hysteria.proulx.com> <1314020833l.1261732l.0l@psu.edu> In-Reply-To: <1314020833l.1261732l.0l@psu.edu> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-Spam-Score: -10.3 (----------) X-Debbugs-Envelope-To: 9334 Cc: 9334@debbugs.gnu.org, Bob Proulx X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -10.3 (----------) On 08/22/2011 07:47 AM, ROGER GRAYDON CHRISTMAN wrote: > Thanks. I guess I misinterpreted "uses a default key of the entire line" > as "uses the entire line as keys by default", in which case if the first column > was equal, it would compare the second, then the third, etc. > > I guess I don't know what "default key of the entire line" means with respect > to -n, > since it apparently didn't treat "1 12" as "112" and "1 4" as 14. > I'm curious to find out what this phrase means in this context. 'sort --debug' is your friend. In the C locale, global -n means 'parse as much of the prefix of the line as can be treated as a number as the primary key, then treat the entire line as the secondary key'. $ printf ' 1 12\n 1 4\n 5 16\n 9 20\n' | LC_ALL=C sort --debug -n sort: using simple byte comparison 1 4 _ _____ 1 12 _ _____ 5 16 _ _____ 9 20 _ _____ -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org From unknown Fri Jun 20 07:09:29 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Tue, 20 Sep 2011 11:24:03 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator