GNU bug report logs - #33025
doc: sort: add examples for -R/--random sort

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: coreutils; Severity: wishlist; Reported by: 積丹尼 Dan Jacobson <jidanni@HIDDEN>; dated Fri, 12 Oct 2018 16:29:02 UTC; Maintainer for coreutils is bug-coreutils@HIDDEN.

Message received at 33025 <at> debbugs.gnu.org:


Received: (at 33025) by debbugs.gnu.org; 31 Dec 2018 00:26:21 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Dec 30 19:26:21 2018
Received: from localhost ([127.0.0.1]:42719 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1gdlPR-0004WN-0u
	for submit <at> debbugs.gnu.org; Sun, 30 Dec 2018 19:26:21 -0500
Received: from quail.birch.relay.mailchannels.net ([23.83.209.151]:49007)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <jidanni@HIDDEN>) id 1gdlPO-0004WB-MZ
 for 33025 <at> debbugs.gnu.org; Sun, 30 Dec 2018 19:26:19 -0500
X-Sender-Id: dreamhost|x-authsender|jidanni@HIDDEN
Received: from relay.mailchannels.net (localhost [127.0.0.1])
 by relay.mailchannels.net (Postfix) with ESMTP id 56D7A123EF9;
 Mon, 31 Dec 2018 00:26:17 +0000 (UTC)
Received: from pdx1-sub0-mail-a40.g.dreamhost.com (unknown [100.96.33.121])
 (Authenticated sender: dreamhost)
 by relay.mailchannels.net (Postfix) with ESMTPA id 08AC2122AFA;
 Mon, 31 Dec 2018 00:26:17 +0000 (UTC)
X-Sender-Id: dreamhost|x-authsender|jidanni@HIDDEN
Received: from pdx1-sub0-mail-a40.g.dreamhost.com (pop.dreamhost.com
 [64.90.62.162]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384)
 by 0.0.0.0:2500 (trex/5.16.2); Mon, 31 Dec 2018 00:26:17 +0000
X-MC-Relay: Neutral
X-MailChannels-SenderId: dreamhost|x-authsender|jidanni@HIDDEN
X-MailChannels-Auth-Id: dreamhost
X-Tasty-Wipe: 43be354e7cba5e03_1546215977157_2406975762
X-MC-Loop-Signature: 1546215977157:428449685
X-MC-Ingress-Time: 1546215977156
Received: from pdx1-sub0-mail-a40.g.dreamhost.com (localhost [127.0.0.1])
 by pdx1-sub0-mail-a40.g.dreamhost.com (Postfix) with ESMTP id 960E8803EB;
 Sun, 30 Dec 2018 16:26:16 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=jidanni.org; h=from:to:cc
 :subject:references:date:message-id:mime-version:content-type;
 s=jidanni.org; bh=UDbuwHIaqwWjnUv3261URVIZ1v8=; b=WBeNSapaR7b32
 WuB6xGU5dtD7DgXFJJKzMHZuTKKG0C8jFMQvYVb+IGso1/OTpVWLTmX8JfLzR0n6
 raL8hZejDKYR5dxWnQsPF8QHVY2B9tzUtrW5bRH98n4t47aJU0CryUaTXaqULtIs
 asQcjeqnTNfKwzrXs6WvA0jFj0cmn8=
Received: from jidanni.org (39-9-13-21.adsl.fetnet.net [39.9.13.21])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (No client certificate requested)
 (Authenticated sender: jidanni@HIDDEN)
 by pdx1-sub0-mail-a40.g.dreamhost.com (Postfix) with ESMTPSA id BE7B180332;
 Sun, 30 Dec 2018 16:26:15 -0800 (PST)
X-DH-BACKEND: pdx1-sub0-mail-a40
From: =?utf-8?B?56mN5Li55bC8?= Dan Jacobson <jidanni@HIDDEN>
To: Assaf Gordon <assafgordon@HIDDEN>
Subject: Re: bug#33025: Add examples of why one would want to "sort" something
 "randomly"
References: <87zhvjnn7z.fsf@HIDDEN>
 <542dbcd8-034d-3769-2566-969295c8c04f@HIDDEN>
Date: Mon, 31 Dec 2018 08:26:05 +0800
Message-ID: <87y386y21u.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
X-VR-OUT-STATUS: OK
X-VR-OUT-SCORE: -100
X-VR-OUT-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtledruddugddvfecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucggtfgfnhhsuhgsshgtrhhisggvpdfftffgtefojffquffvnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvffufhffkfggtgesthdtredttddtjeenucfhrhhomhepnjjnnjcuffgrnhculfgrtghosghsohhnuceojhhiuggrnhhnihesjhhiuggrnhhnihdrohhrgheqnecuffhomhgrihhnpehgohhoghhlvgdrtghomhenucfkphepfeelrdelrddufedrvddunecurfgrrhgrmhepmhhouggvpehsmhhtphdphhgvlhhopehjihgurghnnhhirdhorhhgpdhinhgvthepfeelrdelrddufedrvddupdhrvghtuhhrnhdqphgrthhhpeeprehuthhfqdekreeureehiehmpfehnfhiheehsgevkeerpecuffgrnhculfgrtghosghsohhnuceojhhiuggrnhhnihesjhhiuggrnhhnihdrohhrgheqpdhmrghilhhfrhhomhepjhhiuggrnhhnihesjhhiuggrnhhnihdrohhrghdpnhhrtghpthhtohepfeeftddvheesuggvsggsuhhgshdrghhnuhdrohhrghenucevlhhushhtvghrufhiiigvpedt
X-Spam-Score: 0.1 (/)
X-Debbugs-Envelope-To: 33025
Cc: 33025 <at> debbugs.gnu.org
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.9 (/)

>>>>> "AG" == Assaf Gordon <assafgordon@HIDDEN> writes:

AG> (It doesn't deal with "why", that is left to the users to decide when
AG> they need it, but it shows clear examples of how to use it).

Maybe add "For example, you might want to hear your songs in a fresh fun
order. Or make sure your program still works even if the moms come
between or after the pops..."
https://www.google.com/search?q=reasons+for+random+order




Information forwarded to bug-coreutils@HIDDEN:
bug#33025; Package coreutils. Full text available.

Message received at 33025 <at> debbugs.gnu.org:


Received: (at 33025) by debbugs.gnu.org; 30 Dec 2018 19:58:35 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Dec 30 14:58:35 2018
Received: from localhost ([127.0.0.1]:42650 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1gdhEI-0004BH-VD
	for submit <at> debbugs.gnu.org; Sun, 30 Dec 2018 14:58:35 -0500
Received: from zimbra.cs.ucla.edu ([131.179.128.68]:40144)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eggert@HIDDEN>) id 1gdhEG-0004B1-T7
 for 33025 <at> debbugs.gnu.org; Sun, 30 Dec 2018 14:58:33 -0500
Received: from localhost (localhost [127.0.0.1])
 by zimbra.cs.ucla.edu (Postfix) with ESMTP id 7212C160BC2;
 Sun, 30 Dec 2018 11:58:26 -0800 (PST)
Received: from zimbra.cs.ucla.edu ([127.0.0.1])
 by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032)
 with ESMTP id tMr4Wm6DmiRm; Sun, 30 Dec 2018 11:58:25 -0800 (PST)
Received: from localhost (localhost [127.0.0.1])
 by zimbra.cs.ucla.edu (Postfix) with ESMTP id D3F96160E4C;
 Sun, 30 Dec 2018 11:58:24 -0800 (PST)
X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu
Received: from zimbra.cs.ucla.edu ([127.0.0.1])
 by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026)
 with ESMTP id Cwhyu2zCHSZa; Sun, 30 Dec 2018 11:58:24 -0800 (PST)
Received: from [192.168.1.9] (cpe-23-242-74-103.socal.res.rr.com
 [23.242.74.103])
 by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 98058160BC2;
 Sun, 30 Dec 2018 11:58:24 -0800 (PST)
Subject: Re: bug#33025: Add examples of why one would want to "sort" something
 "randomly"
To: Assaf Gordon <assafgordon@HIDDEN>,
 =?UTF-8?B?56mN5Li55bC8IERhbiBKYWNvYnNvbg==?= <jidanni@HIDDEN>,
 33025 <at> debbugs.gnu.org
References: <87zhvjnn7z.fsf@HIDDEN>
 <542dbcd8-034d-3769-2566-969295c8c04f@HIDDEN>
From: Paul Eggert <eggert@HIDDEN>
Organization: UCLA Computer Science Department
Message-ID: <ca68d955-d2d4-19a6-caec-88eec0bbea3a@HIDDEN>
Date: Sun, 30 Dec 2018 11:58:24 -0800
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101
 Thunderbird/60.2.1
MIME-Version: 1.0
In-Reply-To: <542dbcd8-034d-3769-2566-969295c8c04f@HIDDEN>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: 7bit
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 33025
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: -3.3 (---)

Thanks. Minor comments. The word "groupped" is a misspelling. Instead of " 
@samp{5},@samp{3},@samp{7} - exactly", write " 
@samp{5},@samp{3},@samp{7}--exactly"; that is, use an em dash rather than space, 
hyphen, space. Also, the style in .texi files is to put two spaces (or a 
newline) at the end of each sentence.




Information forwarded to bug-coreutils@HIDDEN:
bug#33025; Package coreutils. Full text available.

Message received at 33025 <at> debbugs.gnu.org:


Received: (at 33025) by debbugs.gnu.org; 30 Dec 2018 19:27:08 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Dec 30 14:27:08 2018
Received: from localhost ([127.0.0.1]:42630 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1gdgjr-00036F-NN
	for submit <at> debbugs.gnu.org; Sun, 30 Dec 2018 14:27:08 -0500
Received: from mail-pl1-f173.google.com ([209.85.214.173]:33166)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <assafgordon@HIDDEN>) id 1gdgjp-00035k-GO
 for 33025 <at> debbugs.gnu.org; Sun, 30 Dec 2018 14:27:06 -0500
Received: by mail-pl1-f173.google.com with SMTP id z23so11988053plo.0
 for <33025 <at> debbugs.gnu.org>; Sun, 30 Dec 2018 11:27:05 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=subject:to:references:from:message-id:date:user-agent:mime-version
 :in-reply-to:content-language;
 bh=VGtja5oJaTv9C3oqqe19rVfGzNFg5J+vF98ggqSyLE0=;
 b=SP6D62IwjLXavws1/yHIKQR7CYxhk7XB1z1kbriOnb9vJo3SnLmLPg+KFqDXXsLSRt
 nOxASAJ6Wny0z0tSNMZuB7UZLKODq6xR64lx0xO1zC+X/tpsZgFl20aOCN5WWfEzgYi+
 pEEWD1TzwlJDWgrQj+HlmsdEes33E+qLB+dSHtpm5l7LLLCYflq40OfzZN8/k9/gDOxn
 XcMR1GQQP2M2Kq/9HuQKqjo9tDQp58l5Zw2oYF9kQ3Poxmg/mwbHjFzah50NRo44eC9a
 G29Ae1fwhPXrR7pdUCYeCQZJQozo8Q6w7fjd7QJRANFO0JLs90SAU6QmYvr81y5doSuX
 m/Ww==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:subject:to:references:from:message-id:date
 :user-agent:mime-version:in-reply-to:content-language;
 bh=VGtja5oJaTv9C3oqqe19rVfGzNFg5J+vF98ggqSyLE0=;
 b=TRSJLCouBZUd6LPe+nwzre4yC3co6iTp5l3ok30aX/1dKRTBPGZmHMf7ngzSaA9EOV
 CTgqNDt0Bqg9WhixwhfPUlEKmEnMKp5GHT/sr700p6QZy99i63LZ6P/A2p39ZqZLhvTr
 gqFkzD2jkFLIhyDPNhkWtpeuQpMEWwZP8pKmDTjQfoB4uL2LfqppkuKlIX1TfODvwYb7
 ZXJOLhDog9kwkr+W0zx3AESeH7E74+gfKYruqy+1mVLJqB3tOG2yPrm9i+bs9A1LTKYN
 txNgaogPZH7EN+2QvkfyahsvZQIOHb9giz0XqzYjiL+tNxwPTfUMaFzKNTM92ANx61eB
 wEEA==
X-Gm-Message-State: AJcUukfILU2yTLXcmvXOI9h6gpk4vLFofsfVZmryMh3p1yUMUMBI8ziY
 QSLgu198CRdx9D0jVVvi33A3Yhqb
X-Google-Smtp-Source: ALg8bN53yL8ccd34clV0TJEsscT/BJHnncW6VkkCwJJqIYBMATNaaetpmSpkU7Wie3w0MpFKLEB7tw==
X-Received: by 2002:a17:902:33c2:: with SMTP id
 b60mr34931389plc.211.1546198019109; 
 Sun, 30 Dec 2018 11:26:59 -0800 (PST)
Received: from tomato.housegordon.com (moose.housegordon.com. [184.68.105.38])
 by smtp.googlemail.com with ESMTPSA id
 q7sm58477575pgp.40.2018.12.30.11.26.56
 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
 Sun, 30 Dec 2018 11:26:57 -0800 (PST)
Subject: Re: bug#33025: Add examples of why one would want to "sort" something
 "randomly"
To: =?UTF-8?B?56mN5Li55bC8IERhbiBKYWNvYnNvbg==?= <jidanni@HIDDEN>,
 33025 <at> debbugs.gnu.org
References: <87zhvjnn7z.fsf@HIDDEN>
From: Assaf Gordon <assafgordon@HIDDEN>
Message-ID: <542dbcd8-034d-3769-2566-969295c8c04f@HIDDEN>
Date: Sun, 30 Dec 2018 12:26:55 -0700
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101
 Thunderbird/60.3.0
MIME-Version: 1.0
In-Reply-To: <87zhvjnn7z.fsf@HIDDEN>
Content-Type: multipart/mixed; boundary="------------8896180FEA94DB90AEAC25B9"
Content-Language: en-US
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 33025
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: -1.0 (-)

This is a multi-part message in MIME format.
--------------8896180FEA94DB90AEAC25B9
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit

Hello,

On 2018-10-12 10:28 a.m., 積丹尼 Dan Jacobson wrote:
> 
> OK, but you need to mention some examples of why someone would want to
> "sort" something "randomly".
 >

Attached is a patch to add examples of shuf/sort -R
to the coreutils documentation.

(It doesn't deal with "why", that is left to the users to decide when 
they need it, but it shows clear examples of how to use it).

regards,
  - assaf

--------------8896180FEA94DB90AEAC25B9
Content-Type: text/x-patch;
 name="0001-doc-add-examples-of-shuf-sort-R.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="0001-doc-add-examples-of-shuf-sort-R.patch"

From a8ae1f29a96b47b9a9c2b26875bd41bfa124e83b Mon Sep 17 00:00:00 2001
From: Assaf Gordon <assafgordon@HIDDEN>
Date: Sun, 30 Dec 2018 12:21:31 -0700
Subject: [PATCH] doc: add examples of shuf/sort -R

Requested by Dan Jacobson <jidanni@HIDDEN> in
https://bugs.gnu.org/33025 .

* doc/coreutils.texi (randomizing files): New section.
---
 doc/coreutils.texi | 148 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 148 insertions(+)

diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 8d303cd56..e05b34ab1 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -276,6 +276,7 @@ Operating on sorted files
 * comm invocation::              Compare two sorted files line by line
 * ptx invocation::               Produce a permuted index of file contents
 * tsort invocation::             Topological sort
+* randomizing files::            Producing random output
 
 @command{ptx}: Produce permuted indexes
 
@@ -4192,6 +4193,7 @@ These commands work with (or produce) sorted files.
 * comm invocation::             Compare two sorted files line by line.
 * ptx invocation::              Produce a permuted index of file contents.
 * tsort invocation::            Topological sort.
+* randomizing files::            Producing random output
 @end menu
 
 
@@ -6018,6 +6020,152 @@ Anyhow, that's where tsort came from.  To solve an old problem with
 the way the linker handled archive files, which has since been solved
 in different ways.
 
+@node randomizing files
+@section Producing random output
+
+The @command{shuf} and @command{sort -R/--random-sort} commands read input
+(sorted or not) and output its lines in a randomized order.
+@command{shuf} shuffles all input lines equally, regardless of their content.
+@command{sort -R} shuffles the @emph{keys} of the input lines -
+lines with identical sort keys will be grouped together:
+
+@multitable @columnfractions .5 .5
+@item
+@example
+$ printf '%s\n' A A A B B C D D | shuf
+A
+C
+D
+D
+A
+B
+A
+B
+@end example
+@tab
+@example
+$ printf '%s\n' A A A B B C D D | sort -R
+C
+D
+D
+A
+A
+A
+B
+B
+@end example
+@end multitable
+
+@command{shuf -n @var{count}} outputs at most @var{count} number of lines (i.e.,
+a sub-sample). @command{sort --random-sort --uniq} outputs one line of each
+group in a random order:
+
+@multitable @columnfractions .5 .5
+@item
+@example
+$ printf '%s\n' A A A B B C D D | shuf -n5
+B
+D
+A
+D
+B
+@end example
+@tab
+@example
+$ printf '%s\n' A A A B B C D D | sort -R -u
+C
+A
+B
+D
+@end example
+@end multitable
+
+@command{sort} operates on keys. Random and non-random keys can be combined
+to achieve desired results. In the following examples, the input file @file{in}
+contains these lines:
+
+@example
+$ cat in
+A 5
+A 3
+A 7
+B 6
+B 4
+C 4
+D 9
+D 8
+@end example
+
+@command{sort -R} without explicit keys operates on entire lines,
+producing unexpected results (as @samp{A 5} and @samp{A 3} do not result
+in identical key value):
+
+@example
+$ sort -R in
+A 7
+C 4
+A 3
+D 8
+B 6
+B 4
+A 5
+D 9
+@end example
+
+Specifing explicit key to sort randomly results in the keyed
+colomn (letters) in random order (yet same keys groupped together),
+and the other column (digits) sorted alphabetically (the default
+last-resort sort):
+
+@example
+$ sort -k1,1R in
+C 4
+A 3
+A 5
+A 7
+B 4
+B 6
+D 8
+D 9
+@end example
+
+
+In the following example, the first columns (letters) are sorted in
+reverse alphabetical order, and the second column (digits) are sorted
+randomly:
+
+@example
+$ sort -k1,1r -k2,2R in
+D 8
+D 9
+C 4
+B 6
+B 4
+A 7
+A 3
+A 5
+@end example
+
+
+To randomize a single column and keep the input order of all other
+columns, use the @option{-s/--stable} option. In the following example
+the letters will be groupped in random order, while the digits will
+be in the same order as the input file (i.e., the digits in group @samp{A}
+will always be @samp{5},@samp{3},@samp{7} - exactly as in the input file):
+
+@example
+$ sort -k1,1R -s in
+D 9
+D 8
+B 6
+B 4
+A 5
+A 3
+A 7
+C 4
+@end example
+
+
 
 @node Operating on fields
 @chapter Operating on fields
-- 
2.11.0


--------------8896180FEA94DB90AEAC25B9--




Information forwarded to bug-coreutils@HIDDEN:
bug#33025; Package coreutils. Full text available.
Changed bug title to 'doc: sort: add examples for -R/--random sort' from 'Add examples of why one would want to "sort" something "randomly"' Request was from Assaf Gordon <assafgordon@HIDDEN> to control <at> debbugs.gnu.org. Full text available.
Severity set to 'wishlist' from 'normal' Request was from Assaf Gordon <assafgordon@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 12 Oct 2018 16:29:01 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Oct 12 12:29:01 2018
Received: from localhost ([127.0.0.1]:47405 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1gB0JA-0007Qh-Ol
	for submit <at> debbugs.gnu.org; Fri, 12 Oct 2018 12:29:00 -0400
Received: from eggs.gnu.org ([208.118.235.92]:42043)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <jidanni@HIDDEN>) id 1gB0J9-0007QV-Ko
 for submit <at> debbugs.gnu.org; Fri, 12 Oct 2018 12:28:59 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <jidanni@HIDDEN>) id 1gB0J3-0003kw-QQ
 for submit <at> debbugs.gnu.org; Fri, 12 Oct 2018 12:28:54 -0400
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: *
X-Spam-Status: No, score=1.8 required=5.0 tests=BAYES_50,FROM_EXCESS_BASE64
 autolearn=disabled version=3.3.2
Received: from lists.gnu.org ([2001:4830:134:3::11]:39914)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <jidanni@HIDDEN>) id 1gB0J3-0003ko-Mv
 for submit <at> debbugs.gnu.org; Fri, 12 Oct 2018 12:28:53 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:51652)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <jidanni@HIDDEN>) id 1gB0J2-0005bu-Ql
 for bug-coreutils@HIDDEN; Fri, 12 Oct 2018 12:28:53 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <jidanni@HIDDEN>) id 1gB0Ix-0003fe-Og
 for bug-coreutils@HIDDEN; Fri, 12 Oct 2018 12:28:52 -0400
Received: from glow.birch.relay.mailchannels.net ([23.83.209.71]:26698)
 by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <jidanni@HIDDEN>) id 1gB0Ix-0003cU-CL
 for bug-coreutils@HIDDEN; Fri, 12 Oct 2018 12:28:47 -0400
X-Sender-Id: dreamhost|x-authsender|jidanni@HIDDEN
Received: from relay.mailchannels.net (localhost [127.0.0.1])
 by relay.mailchannels.net (Postfix) with ESMTP id D3E205021D7
 for <bug-coreutils@HIDDEN>; Fri, 12 Oct 2018 16:28:42 +0000 (UTC)
Received: from pdx1-sub0-mail-a70.g.dreamhost.com (unknown [100.96.29.126])
 (Authenticated sender: dreamhost)
 by relay.mailchannels.net (Postfix) with ESMTPA id 854885017E9
 for <bug-coreutils@HIDDEN>; Fri, 12 Oct 2018 16:28:42 +0000 (UTC)
X-Sender-Id: dreamhost|x-authsender|jidanni@HIDDEN
Received: from pdx1-sub0-mail-a70.g.dreamhost.com (pop.dreamhost.com
 [64.90.62.162]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384)
 by 0.0.0.0:2500 (trex/5.16.2); Fri, 12 Oct 2018 16:28:42 +0000
X-MC-Relay: Neutral
X-MailChannels-SenderId: dreamhost|x-authsender|jidanni@HIDDEN
X-MailChannels-Auth-Id: dreamhost
X-Gusty-Bitter: 2e862d3455384498_1539361722656_3374393718
X-MC-Loop-Signature: 1539361722655:185783577
X-MC-Ingress-Time: 1539361722655
Received: from pdx1-sub0-mail-a70.g.dreamhost.com (localhost [127.0.0.1])
 by pdx1-sub0-mail-a70.g.dreamhost.com (Postfix) with ESMTP id BFE1C8016C
 for <bug-coreutils@HIDDEN>; Fri, 12 Oct 2018 09:28:41 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=jidanni.org; h=from:to
 :subject:date:message-id:mime-version:content-type
 :content-transfer-encoding; s=jidanni.org; bh=DnJuWX4HwPCuglM+Bm
 OttgZ1VyI=; b=or7gt/yCDlhMkbTedZSQZs9QP3TREOtwm2VRHvzN+Xki3Ntj+z
 vyNFc3U66N9kHKWN5TjESg5EE3yAZCsDofj42VW4P8agJzaaIfXPc1/vQt7qYT2A
 s8ep6BZYEdm0qlehtumJOvGxKu/O+NXu3qTcjuUTwd15MBjQib5EeC2Bc=
Received: from jidanni.org (220-140-1-63.dynamic-ip.hinet.net [220.140.1.63])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256
 bits)) (No client certificate requested)
 (Authenticated sender: jidanni@HIDDEN)
 by pdx1-sub0-mail-a70.g.dreamhost.com (Postfix) with ESMTPSA id 5ECBF80160
 for <bug-coreutils@HIDDEN>; Fri, 12 Oct 2018 09:28:41 -0700 (PDT)
X-DH-BACKEND: pdx1-sub0-mail-a70
From: =?utf-8?B?56mN5Li55bC8?= Dan Jacobson <jidanni@HIDDEN>
To: bug-coreutils@HIDDEN
Subject: Add examples of why one would want to "sort" something "randomly"
Date: Sat, 13 Oct 2018 00:28:32 +0800
Message-ID: <87zhvjnn7z.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
X-VR-OUT-STATUS: OK
X-VR-OUT-SCORE: 0
X-VR-OUT-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtkedrvddugdejiecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucggtfgfnhhsuhgsshgtrhhisggvpdfftffgtefojffquffvnecuuegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkfggtgfgsehtkeertddttdejnecuhfhrohhmpejnnjjnucffrghnucflrggtohgsshhonhcuoehjihgurghnnhhisehjihgurghnnhhirdhorhhgqeenucfkphepvddvtddrudegtddruddrieefnecurfgrrhgrmhepmhhouggvpehsmhhtphdphhgvlhhopehjihgurghnnhhirdhorhhgpdhinhgvthepvddvtddrudegtddruddrieefpdhrvghtuhhrnhdqphgrthhhpeeprehuthhfqdekreeureehiehmpfehnfhiheehsgevkeerpecuffgrnhculfgrtghosghsohhnuceojhhiuggrnhhnihesjhhiuggrnhhnihdrohhrgheqpdhmrghilhhfrhhomhepjhhiuggrnhhnihesjhhiuggrnhhnihdrohhrghdpnhhrtghpthhtohepsghughdqtghorhgvuhhtihhlshesghhnuhdrohhrghenucevlhhushhtvghrufhiiigvpedt
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 2001:4830:134:3::11
X-Spam-Score: -4.9 (----)
X-Debbugs-Envelope-To: submit
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: -5.9 (-----)

On (info "(coreutils) sort invocation")

=E2=80=98-R=E2=80=99
=E2=80=98--random-sort=E2=80=99
=E2=80=98--sort=3Drandom=E2=80=99
     Sort by hashing the input keys and then sorting the hash values.
     Choose the hash function at random, ensuring that it is free of
     collisions so that differing keys have differing hash values.  This
     is like a random permutation of the inputs (*note shuf
     invocation::), except that keys with the same value sort
     together...

OK, but you need to mention some examples of why someone would want to
"sort" something "randomly".

OK, I have one:

You have a list of URLs.

You know there are probably duplicates in there, that you want to get
rid of.

But you also don't want to make it look like you have "machine sorted
them." You want them to still look "hand assembled."

So you use sort --random-sort --unique on them!




Acknowledgement sent to 積丹尼 Dan Jacobson <jidanni@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-coreutils@HIDDEN. Full text available.
Report forwarded to bug-coreutils@HIDDEN:
bug#33025; Package coreutils. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Mon, 25 Nov 2019 12:00:02 UTC

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