X-Loop: help-debbugs@HIDDEN Subject: bug#67690: Bug in command sort? Resent-From: Oleg Moiseichuk <MetamAdeptus@HIDDEN> Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> Resent-CC: bug-coreutils@HIDDEN Resent-Date: Thu, 07 Dec 2023 14:51:01 +0000 Resent-Message-ID: <handler.67690.B.170196061230708 <at> debbugs.gnu.org> Resent-Sender: help-debbugs@HIDDEN X-GNU-PR-Message: report 67690 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: 67690 <at> debbugs.gnu.org X-Debbugs-Original-To: bug-coreutils@HIDDEN Received: via spool by submit <at> debbugs.gnu.org id=B.170196061230708 (code B ref -1); Thu, 07 Dec 2023 14:51:01 +0000 Received: (at submit) by debbugs.gnu.org; 7 Dec 2023 14:50:12 +0000 Received: from localhost ([127.0.0.1]:41406 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1rBFhb-0007zB-Ju for submit <at> debbugs.gnu.org; Thu, 07 Dec 2023 09:50:12 -0500 Received: from lists.gnu.org ([2001:470:142::17]:44412) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <MetamAdeptus@HIDDEN>) id 1rBFUx-0007QK-FK for submit <at> debbugs.gnu.org; Thu, 07 Dec 2023 09:37:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <MetamAdeptus@HIDDEN>) id 1rBFUd-0005vt-CK for bug-coreutils@HIDDEN; Thu, 07 Dec 2023 09:36:48 -0500 Received: from mout.gmx.net ([212.227.17.20]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <MetamAdeptus@HIDDEN>) id 1rBFUa-0004eP-Kt for bug-coreutils@HIDDEN; Thu, 07 Dec 2023 09:36:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=s31663417; t=1701959801; x=1702564601; i=metamadeptus@HIDDEN; bh=a6KWPsEmCk00bylVeKzK6zW0czm697sicKOKYPKKu3c=; h=X-UI-Sender-Class:From:Subject:To:Date; b=loayUltZS9banQG5cBqW2lVWhCXeUC+kNpKnH6eI0TCUrBC8mgUvw66w39+Vab0k +2AhTmJkoRVNTvNIuykBXcq5uUVOU7ZLmMl5EiDQvTP2JGpNvFsLsEIoUTsj+Uge+ 3HanWSoQEGzTXFV/I8SxRqA/bIJS008H/eIbflIB316E5t/o6DazT4eNNnKr9Wfj5 RBtOe1A9HU1rf47JLWlBHbq/FFuC9BDC3//9OcSTJnx3WAY49gz7rxq6coeZJ+ldU kBtt8z2B3nzwB3tvBX/dCS8JKZzMLTGxCGUf7+Vk4IhpgBU+3+y5leW5Rdwm1GdSm Da0NzXpSJ5eDVOauIQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [80.94.160.11] ([80.94.160.11]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1Mqs4f-1rWqz33ofJ-00msDB for <bug-coreutils@HIDDEN>; Thu, 07 Dec 2023 15:36:41 +0100 From: Oleg Moiseichuk <MetamAdeptus@HIDDEN> Message-ID: <f13aecda-67c6-4d05-5d4e-95ee2ac62c93@HIDDEN> Date: Thu, 7 Dec 2023 17:36:39 +0300 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------7DB0FF98F85685B371F87B48" X-Provags-ID: V03:K1:gJmnk59RQ2UVf2q6vN/PrWYU2pVTUe4wD5SspAgEzVs+BNfFrbL nqHGDOIaDhfjmaWrKgUyL8Pfg04obNT1BrpS7ntGTaf8c+lCJUNfp1tjlBFDZKyELbcVbly Gz95FWekUedtVnmZyjlB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T6r0oj9YQKDIzrRZ40Nf5S/U/IbA6oY1d7jBx2 nBGo2A== Received-SPF: pass client-ip=212.227.17.20; envelope-from=MetamAdeptus@HIDDEN; helo=mout.gmx.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.0 (+) X-Mailman-Approved-At: Thu, 07 Dec 2023 09:50:10 -0500 X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -0.0 (/) This is a multi-part message in MIME format. --------------7DB0FF98F85685B371F87B48 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello! I've got a list of IP addresses, each of them is prepended by its frequenc= y counter (please find attached in the file list-1.txt). I need to sort th= em from most frequent to least. I tried using this command: sort -t '.' -n -k 1.1,1.8r -k 1.9 -k 2,2 -k 3,3 -k 4,4 list-1.txt But I've got some weird results. Ok, I merged these counters with IP addresses using awk (file list-2.txt).= Now they use the same separator and I can simplify the command: sort -t '.' -n -k 1,1r -k 2,2 -k 3,3 -k 4,4 -k 5,5 list-2.txt > sorted-a.t= xt It looks like as sorted properly but some entries with the counters 13 and= 10 are misplaced. Strangely enough, when I use direct order, they are sorted correctly: sort -t '.' -n -k 1,1 -k 2,2 -k 3,3 -k 4,4 -k 5,5 list-2.txt > sorted-b.tx= t Is it a bug or I'm doing something wrong? I checked this in Ubuntu 22.04, sort version is 8.32. =2D- Best regards, Oleg Moiseichuk --------------7DB0FF98F85685B371F87B48 Content-Type: text/plain; charset=UTF-8; name="list-1.txt" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="list-1.txt" ICAgICAgMiA4MC45NC4xNjAuMjA3CiAgICAgIDEgODAuOTQuMTY2LjE3NQogICAgICA1IDgw Ljk0LjE2Ny44NwogICAgIDEwIDgwLjk0LjE3MS4xMjIKICAgICAgMyA4MC45NC4xNzQuNzYK ICAgICAgNyA4MC45NC4xNzQuODIKICAgICAgMSA4MC45NC4xNzQuODYKICAgICAgMSA4MC45 NC4xNzQuOTAKICAgICAxMyA4MC45NC4xNzQuOTcKICAgICAgMiA5NS4xMzAuODcuNwo= --------------7DB0FF98F85685B371F87B48 Content-Type: text/plain; charset=UTF-8; name="list-2.txt" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="list-2.txt" Mi44MC45NC4xNjAuMjA3CjEuODAuOTQuMTY2LjE3NQo1LjgwLjk0LjE2Ny44NwoxMC44MC45 NC4xNzEuMTIyCjMuODAuOTQuMTc0Ljc2CjcuODAuOTQuMTc0LjgyCjEuODAuOTQuMTc0Ljg2 CjEuODAuOTQuMTc0LjkwCjEzLjgwLjk0LjE3NC45NwoyLjk1LjEzMC44Ny43Cg== --------------7DB0FF98F85685B371F87B48 Content-Type: text/plain; charset=UTF-8; name="sorted-a.txt" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="sorted-a.txt" Ny44MC45NC4xNzQuODIKNS44MC45NC4xNjcuODcKMy44MC45NC4xNzQuNzYKMi44MC45NC4x NjAuMjA3CjIuOTUuMTMwLjg3LjcKMTMuODAuOTQuMTc0Ljk3CjEwLjgwLjk0LjE3MS4xMjIK MS44MC45NC4xNjYuMTc1CjEuODAuOTQuMTc0Ljg2CjEuODAuOTQuMTc0LjkwCg== --------------7DB0FF98F85685B371F87B48 Content-Type: text/plain; charset=UTF-8; name="sorted-b.txt" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="sorted-b.txt" MS44MC45NC4xNjYuMTc1CjEuODAuOTQuMTc0Ljg2CjEuODAuOTQuMTc0LjkwCjIuODAuOTQu MTYwLjIwNwoyLjk1LjEzMC44Ny43CjMuODAuOTQuMTc0Ljc2CjUuODAuOTQuMTY3Ljg3Cjcu ODAuOTQuMTc0LjgyCjEwLjgwLjk0LjE3MS4xMjIKMTMuODAuOTQuMTc0Ljk3Cg== --------------7DB0FF98F85685B371F87B48--
Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) Content-Type: text/plain; charset=utf-8 X-Loop: help-debbugs@HIDDEN From: help-debbugs@HIDDEN (GNU bug Tracking System) To: Oleg Moiseichuk <MetamAdeptus@HIDDEN> Subject: bug#67690: Acknowledgement (Bug in command sort?) Message-ID: <handler.67690.B.170196061230708.ack <at> debbugs.gnu.org> References: <f13aecda-67c6-4d05-5d4e-95ee2ac62c93@HIDDEN> X-Gnu-PR-Message: ack 67690 X-Gnu-PR-Package: coreutils Reply-To: 67690 <at> debbugs.gnu.org Date: Thu, 07 Dec 2023 14:51:02 +0000 Thank you for filing a new bug report with debbugs.gnu.org. This is an automatically generated reply to let you know your message has been received. Your message is being forwarded to the package maintainers and other interested parties for their attention; they will reply in due course. Your message has been sent to the package maintainer(s): bug-coreutils@HIDDEN If you wish to submit further information on this problem, please send it to 67690 <at> debbugs.gnu.org. Please do not send mail to help-debbugs@HIDDEN unless you wish to report a problem with the Bug-tracking system. --=20 67690: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D67690 GNU Bug Tracking System Contact help-debbugs@HIDDEN with problems
X-Loop: help-debbugs@HIDDEN Subject: bug#67690: Bug in command sort? Resent-From: =?UTF-8?Q?P=C3=A1draig?= Brady <P@HIDDEN> Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> Resent-CC: bug-coreutils@HIDDEN Resent-Date: Thu, 07 Dec 2023 15:38:02 +0000 Resent-Message-ID: <handler.67690.B67690.17019634324403 <at> debbugs.gnu.org> Resent-Sender: help-debbugs@HIDDEN X-GNU-PR-Message: followup 67690 X-GNU-PR-Package: coreutils X-GNU-PR-Keywords: To: Oleg Moiseichuk <MetamAdeptus@HIDDEN>, 67690 <at> debbugs.gnu.org Received: via spool by 67690-submit <at> debbugs.gnu.org id=B67690.17019634324403 (code B ref 67690); Thu, 07 Dec 2023 15:38:02 +0000 Received: (at 67690) by debbugs.gnu.org; 7 Dec 2023 15:37:12 +0000 Received: from localhost ([127.0.0.1]:42797 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1rBGR6-00018x-0B for submit <at> debbugs.gnu.org; Thu, 07 Dec 2023 10:37:12 -0500 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]:45393) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <pixelbeat@HIDDEN>) id 1rBGR0-00017z-6l for 67690 <at> debbugs.gnu.org; Thu, 07 Dec 2023 10:37:10 -0500 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-40b5155e154so13333045e9.3 for <67690 <at> debbugs.gnu.org>; Thu, 07 Dec 2023 07:36:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701963408; x=1702568208; darn=debbugs.gnu.org; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :sender:from:to:cc:subject:date:message-id:reply-to; bh=cOb8NKjBZtrW89aNz0PPh+WlUVJRlow7yTnnHHDUTrI=; b=US9Q5Vm8dsUDr2E4RUSI/+hwNR4m2yB4vpfOQfWQ4mZSoS1f/bTX2wVpcUReoF5rok WtmcomGrjmNnngJKUj/Qe2AswpFeZKh0tzR9yagkiQYKnaT9ENY4XnkO+HCgkwABmUEk k6A58lQxq1Qms9DWO11Bi0Lyp2e+PrFCoYyZTgpYLfwUuHrjjMgFhROwyvz9tCW1LCL0 GEqllYIRvw/ny8QRV4FjQqngkLocj9DPyox3qqfrtTQ9JlLdFsrKViJGRZk7KvMPS+m5 xgumx3uDmD6i8yZTZEGkPXbhUsz5w8myHB8YsaDdiBfgiJ+0kCsMhI2/NCzC1WAl7/bu QFgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701963408; x=1702568208; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=cOb8NKjBZtrW89aNz0PPh+WlUVJRlow7yTnnHHDUTrI=; b=oq9lpQhySq9YZmkyo1CnP7Zd+HHLZfrQV6usFC9e/9v/L6Z6oASXfp7hZfblZ/KToO vE1BI3UtwMbV/374ilHsfBfMJHA+eXuNRteK2t/uA/0wytMY//PS5IHZ0o950B+Tdsas vortjXJ1SV/3PLoOHv9bkindZBC7LBp1tWkGf94VhSYvNIyxN4uj4OKKwHWN8un3Xe3x 3xmdJaDLDJ7Neg2vfMFs64Hpmf3cNHsRh2t912IwM2LHCtjvuxnTr2aNpHjxkKGJOv4L f1T5C/qSxrfMhF9nvnC3eSo7uGohISrax/TIQ935I0U5Ri1LJpvK88479u1tibI75PBP QsgA== X-Gm-Message-State: AOJu0YzL1+gww9Kuzxzh4L/3tqon40Hyf05HkOdPuS/TjSjvPoxXTh80 DbDO9hqPcM95I/kUXljlVJX2JBDfvow= X-Google-Smtp-Source: AGHT+IGkQUy03iLAAglmpWaXZxOiFHtAAnjkEozCa99Io/Yzu7jZE2ltE2VvFgp7CKcMF5FTBGkDiQ== X-Received: by 2002:a05:600c:4ec7:b0:40c:7a7:d00e with SMTP id g7-20020a05600c4ec700b0040c07a7d00emr1701589wmq.49.1701963407670; Thu, 07 Dec 2023 07:36:47 -0800 (PST) Received: from [192.168.1.20] (95-44-90-175-dynamic.agg2.lod.rsl-rtd.eircom.net. [95.44.90.175]) by smtp.googlemail.com with ESMTPSA id e22-20020adfa456000000b003333f5f5fd7sm1735991wra.31.2023.12.07.07.36.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Dec 2023 07:36:47 -0800 (PST) Message-ID: <a6f456fa-9013-170f-3ae0-53779d934c4b@HIDDEN> Date: Thu, 7 Dec 2023 15:36:46 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US References: <f13aecda-67c6-4d05-5d4e-95ee2ac62c93@HIDDEN> From: =?UTF-8?Q?P=C3=A1draig?= Brady <P@HIDDEN> In-Reply-To: <f13aecda-67c6-4d05-5d4e-95ee2ac62c93@HIDDEN> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Score: 0.5 (/) X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -0.5 (/) tag 67690 notabug close 67690 stop On 07/12/2023 14:36, Oleg Moiseichuk via GNU coreutils Bug Reports wrote: > Hello! > > I've got a list of IP addresses, each of them is prepended by its frequency counter (please find attached in the file list-1.txt). I need to sort them from most frequent to least. I tried using this command: > sort -t '.' -n -k 1.1,1.8r -k 1.9 -k 2,2 -k 3,3 -k 4,4 list-1.txt > But I've got some weird results. Right, once you have multiple delimiters you generally need to adjust the data > Ok, I merged these counters with IP addresses using awk (file list-2.txt). Now they use the same separator and I can simplify the command: > sort -t '.' -n -k 1,1r -k 2,2 -k 3,3 -k 4,4 -k 5,5 list-2.txt > sorted-a.txt > It looks like as sorted properly but some entries with the counters 13 and 10 are misplaced. > Strangely enough, when I use direct order, they are sorted correctly: > sort -t '.' -n -k 1,1 -k 2,2 -k 3,3 -k 4,4 -k 5,5 list-2.txt > sorted-b.txt You're using the correct approach here, but missed this from the docs: "A position in a sort field specified with ‘-k’ may have any of the option letters ‘MbdfghinRrV’ appended to it, in which case no global ordering options are inherited by that particular field." I.e. the 'r' is cancelling out the global 'n'. So you need to specify both options from that field like: sort -t '.' -n -k 1,1rn -k 2,2 -k 3,3 -k 4,4 -k 5,5 list-2.txt cheers, Pádraig p.s. the --debug option can be useful with sort to help identify what's being compared, and various edge cases.
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997 nCipher Corporation Ltd,
1994-97 Ian Jackson.