From unknown Sun Jun 15 08:53:03 2025 X-Loop: help-debbugs@gnu.org Subject: bug#6393: The meaning of --key of sort command? Resent-From: Peng Yu Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Thu, 10 Jun 2010 16:40:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 6393 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: 6393@debbugs.gnu.org X-Debbugs-Original-To: bug-coreutils@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.127618796418266 (code B ref -1); Thu, 10 Jun 2010 16:40:02 +0000 Received: (at submit) by debbugs.gnu.org; 10 Jun 2010 16:39:24 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OMkmp-0004kZ-Da for submit@debbugs.gnu.org; Thu, 10 Jun 2010 12:39:23 -0400 Received: from mx10.gnu.org ([199.232.76.166]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OMkmn-0004kS-5X for submit@debbugs.gnu.org; Thu, 10 Jun 2010 12:39:21 -0400 Received: from lists.gnu.org ([199.232.76.165]:57864) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1OMkmi-0004DU-KD for submit@debbugs.gnu.org; Thu, 10 Jun 2010 12:39:16 -0400 Received: from [140.186.70.92] (port=34965 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OMkmh-0007tV-35 for bug-coreutils@gnu.org; Thu, 10 Jun 2010 12:39:16 -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.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID, T_TO_NO_BRKTS_FREEMAIL autolearn=unavailable version=3.3.1 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OMkme-0000QH-QK for bug-coreutils@gnu.org; Thu, 10 Jun 2010 12:39:14 -0400 Received: from mail-gy0-f169.google.com ([209.85.160.169]:38915) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OMkme-0000Q5-Ni for bug-coreutils@gnu.org; Thu, 10 Jun 2010 12:39:12 -0400 Received: by gyg4 with SMTP id 4so112520gyg.0 for ; Thu, 10 Jun 2010 09:39:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type; bh=QypGz8H8s1/JvXdq8JSq45GqayVDAyE1TT/le/4nq8w=; b=pKSgyDI6xkvuAL9tJF9SG9w32BWRAMkA0aERnzV2nof48bhGGucILN2g/cvtfQLdTF IDPD9n1WnXZiORuz+I4kh3Gg3HCp2zKJCbb1+TlIOXGxLuVrgpuzIjflxhFg498D5TDM zPVzQGXhWkVN4Oi/0mYabXbwFOP1H7yong4Sk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=BXYVIY4W9a9he9SQnoXzjy/2H3iHSfhcLQvsgGCiSW4Rs8J/1D54FwtwAWmejnjfeA 0rDAyPlyx481EvmRo0dy6HkEnyxqXgqUr2lsreg4040J7/3jYsMCOSCdBypTLEwVYsDU DNfyLMPEoURgA8SjWisUB3jvg5WJ9775Kz0IY= MIME-Version: 1.0 Received: by 10.150.238.3 with SMTP id l3mr2038137ybh.87.1276187951872; Thu, 10 Jun 2010 09:39:11 -0700 (PDT) Received: by 10.151.26.11 with HTTP; Thu, 10 Jun 2010 09:39:11 -0700 (PDT) Date: Thu, 10 Jun 2010 11:39:11 -0500 Message-ID: From: Peng Yu Content-Type: text/plain; charset=ISO-8859-1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Spam-Score: -5.5 (-----) 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: -5.6 (-----) Hi, I don't think that I completely understand what key means. In the following example, I thought that --key=2 should order the lines by the 2nd letter in each line without reordering the lines with the same 2nd letter. But it turns out my understanding is not correct. For example, "u a" was before "a a" sorting, but "u a" is after "a a" after sorting. According to the man page, I'd think the sorting is based on the 2nd column only but the 1st column. Why the 1st column matters in this case? -k, --key=POS1[,POS2] start a key at POS1 (origin 1), end it at POS2 (default end of line) $ cat input.txt u a c c a a e e p a m e a a l e a a $ sort --key=2 input.txt a a a a a a p a u a c c e e l e m e -- Regards, Peng From unknown Sun Jun 15 08:53:03 2025 X-Loop: help-debbugs@gnu.org Subject: bug#6393: The meaning of --key of sort command? Resent-From: Peng Yu Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Thu, 10 Jun 2010 16:46:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 6393 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: bug-coreutils@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.127618834818449 (code B ref -1); Thu, 10 Jun 2010 16:46:02 +0000 Received: (at submit) by debbugs.gnu.org; 10 Jun 2010 16:45:48 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OMkt1-0004nW-MX for submit@debbugs.gnu.org; Thu, 10 Jun 2010 12:45:47 -0400 Received: from mx10.gnu.org ([199.232.76.166]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OMksz-0004nR-SJ for submit@debbugs.gnu.org; Thu, 10 Jun 2010 12:45:46 -0400 Received: from lists.gnu.org ([199.232.76.165]:35200) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1OMksv-0004Iq-1z for submit@debbugs.gnu.org; Thu, 10 Jun 2010 12:45:41 -0400 Received: from [140.186.70.92] (port=33230 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OMkss-0001hU-UY for bug-coreutils@gnu.org; Thu, 10 Jun 2010 12:45:40 -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.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,T_DKIM_INVALID,T_TO_NO_BRKTS_FREEMAIL autolearn=unavailable version=3.3.1 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OMksr-0001MT-Ic for bug-coreutils@gnu.org; Thu, 10 Jun 2010 12:45:38 -0400 Received: from mail-gw0-f41.google.com ([74.125.83.41]:60064) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OMksr-0001MP-GF for bug-coreutils@gnu.org; Thu, 10 Jun 2010 12:45:37 -0400 Received: by gwb15 with SMTP id 15so114752gwb.0 for ; Thu, 10 Jun 2010 09:45:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=MdM7tWSnMF9we1i4ZsRrSy2R3SKk1LqU0icqsv465XE=; b=vGju8un9+e1vG1CFe8zviB/6JnOgfLR86CCMNHqszO1OeLUfJDtsgUkVp1N4Ges/+4 x0ypfidqZrBgZVE2JLBb623/twQPm8JTumQNedY3qy4AU6VrRavJZUgo6zXkMpLVnyKn qdOkXj9stBL/XrOrVG6jWX1vd4bHCj2ZQdyVw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=n5vpP6tXibQ76kAMC7SFSnisRQ4cdMiZ+1LvutXkQCO7CVtewf/65sfrsu6CIThrhq gCl99gEWi1rmaXgEhGdrPJX/1ZCxczkIkrkGeNTJrWcR4YwlYNlpw4KqkTF4/TyLeG7W /l3JCojmOT4Wdj6s2eRPqE4vRQFGpwrpe0dlA= MIME-Version: 1.0 Received: by 10.150.159.7 with SMTP id h7mr2157564ybe.16.1276188336774; Thu, 10 Jun 2010 09:45:36 -0700 (PDT) Received: by 10.151.26.11 with HTTP; Thu, 10 Jun 2010 09:45:36 -0700 (PDT) In-Reply-To: References: Date: Thu, 10 Jun 2010 11:45:36 -0500 Message-ID: From: Peng Yu Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Spam-Score: -5.1 (-----) 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: -5.2 (-----) On Thu, Jun 10, 2010 at 11:39 AM, Peng Yu wrote: > Hi, > > I don't think that I completely understand what key means. In the > following example, I thought that --key=3D2 should order the lines by > the 2nd letter in each line without reordering the lines with the same > 2nd letter. But it turns out my understanding is not correct. For > example, "u a" was before "a a" sorting, but "u a" is after "a a" > after sorting. > > According to the man page, I'd think the sorting is based on the 2nd > column only but the 1st column. Why the 1st column matters in this > case? > > -k, --key=3DPOS1[,POS2] > =A0 =A0 =A0 =A0 =A0 =A0 =A0start a key at POS1 (origin 1), end it at POS2= (default =A0end =A0of > =A0 =A0 =A0 =A0 =A0 =A0 =A0line) > > > $ cat input.txt > u a > c c > a a > e e > p a > m e > a a > l e > a a > $ sort --key=3D2 input.txt > a a > a a > a a > p a > u a > c c > e e > l e > m e I forget to mention the following command gives me the same thing (sorting on the 2nd fieled then the 1st field). But according to info sort, it should not the case. Example: To sort on the second field, use `--key=3D2,2' (`-k 2,2'). See below for more examples. $ sort --key=3D2,2 input.txt a a a a a a p a u a c c e e l e m e --=20 Regards, Peng From unknown Sun Jun 15 08:53:03 2025 X-Loop: help-debbugs@gnu.org Subject: bug#6393: The meaning of --key of sort command? Resent-From: Eric Blake Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-coreutils@gnu.org Resent-Date: Thu, 10 Jun 2010 17:03:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 6393 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: Peng Yu Cc: 6393@debbugs.gnu.org Received: via spool by 6393-submit@debbugs.gnu.org id=B6393.127618935119037 (code B ref 6393); Thu, 10 Jun 2010 17:03:01 +0000 Received: (at 6393) by debbugs.gnu.org; 10 Jun 2010 17:02:31 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OMl9C-0004x0-I7 for submit@debbugs.gnu.org; Thu, 10 Jun 2010 13:02:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OMl9A-0004wu-4U for 6393@debbugs.gnu.org; Thu, 10 Jun 2010 13:02:29 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5AH2M5u008274 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 10 Jun 2010 13:02:23 -0400 Received: from [10.11.11.199] (vpn-11-199.rdu.redhat.com [10.11.11.199]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5AH2MF3011228; Thu, 10 Jun 2010 13:02:22 -0400 Message-ID: <4C111A7F.5090405@redhat.com> Date: Thu, 10 Jun 2010 11:01:51 -0600 From: Eric Blake Organization: Red Hat User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100430 Fedora/3.0.4-3.fc13 Lightning/1.0b2pre Mnenhy/0.8.2 Thunderbird/3.0.4 MIME-Version: 1.0 References: In-Reply-To: X-Enigmail-Version: 1.0.1 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enigD3D6010ED7649276A024DEA4" X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-Spam-Score: -10.1 (----------) 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.1 (----------) This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigD3D6010ED7649276A024DEA4 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 06/10/2010 10:39 AM, Peng Yu wrote: > Hi, >=20 > I don't think that I completely understand what key means. In the > following example, I thought that --key=3D2 should order the lines by > the 2nd letter in each line without reordering the lines with the same > 2nd letter. But it turns out my understanding is not correct. For > example, "u a" was before "a a" sorting, but "u a" is after "a a" > after sorting. '--key=3D2' implies a primary sort key from the second field (not second letter), through the end of the line, with a secondary sort key of the entire line. '--key=3D2,2' implies a primary sort key of just the second= field, with a secondary sort key of the entire line. You want '--key=3D2,2 --stable', which disables the secondary sort over the entire= line. --=20 Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org --------------enigD3D6010ED7649276A024DEA4 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/ iQEcBAEBCAAGBQJMERqEAAoJEKeha0olJ0NqVasIAI1kDciS3j1G5koBblxeAYI3 xKTB0n+xSruvBCCDMWLxbHQSz6L5CltHse/OKmX3eWhcXJ3BRm7Xb0lMDn9iYzkE 7EkoXddXe7TG9XQE1acKtUoxeqOlh6zzmFSseXNLPPY7b8DgRo7fA23z2gOPA0sF QZUp5KMOJr/3sKvVMZK3NC6D0wa0BYUGgKoX2lmSLjEHT92zNlF6/GblUovQCxpT Wo5lNZ9iEohSImU3/mAvMy+Tq0ZpMdJp0TC/lwr+nZQJ9CjahZo2/lioKHzVHIjq RmeECiuePFccp7+59S3XeTe9DFWRKM3InTXbjSomZGzlmoYUUhJacnnbMMLeQ9E= =HYjF -----END PGP SIGNATURE----- --------------enigD3D6010ED7649276A024DEA4-- From debbugs-submit-bounces@debbugs.gnu.org Wed Jul 14 12:02:39 2010 Received: (at control) by debbugs.gnu.org; 14 Jul 2010 16:02:39 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OZ4Pu-0006su-Uv for submit@debbugs.gnu.org; Wed, 14 Jul 2010 12:02:39 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1OZ4Ps-0006sn-Oo for control@debbugs.gnu.org; Wed, 14 Jul 2010 12:02:37 -0400 Received: (qmail 332 invoked from network); 14 Jul 2010 16:02:44 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 14 Jul 2010 16:02:44 -0000 Message-ID: <4C3DDF55.9030304@draigBrady.com> Date: Wed, 14 Jul 2010 17:01:25 +0100 From: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: control@debbugs.gnu.org X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Score: -1.9 (-) X-Debbugs-Envelope-To: control 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: -1.9 (-) close 6393 tags 6393 notabug