]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
doc: sort: give example for sorting on the last field
authorPádraig Brady <P@draigBrady.com>
Tue, 23 Apr 2024 11:58:17 +0000 (12:58 +0100)
committerPádraig Brady <P@draigBrady.com>
Tue, 23 Apr 2024 20:29:33 +0000 (21:29 +0100)
* doc/coreutils.texi (sort invocation): Give a DSU example
for sorting names which may have a variable number of fields.
Addresses https://bugs.gnu.org/70532

doc/coreutils.texi

index 2c6c8b68bbe480cc905b94c2649d9730119472a8..3762c6f96e8251a50ad7825b1a8815f6a721f5b5 100644 (file)
@@ -5151,12 +5151,22 @@ Use the common DSU, Decorate Sort Undecorate idiom to
 sort lines according to their length.
 
 @example
-awk '@{print length, $0@}' /etc/passwd | sort -n | cut -f2- -d' '
+getent passwd |@/
+awk '@{print length, $0@}' | sort -n | cut -f2- -d' '
 @end example
 
 In general this technique can be used to sort data that the @command{sort}
 command does not support, or is inefficient at, sorting directly.
 
+@item
+Use the same DSU idiom as above to sort lines by their last field,
+and in this specific example the presented lines are users' full names.
+
+@example
+getent passwd | grep -v nologin | cut -d: -f5 | grep ' ' |@/
+awk '@{print $NF, $0@}' | sort -k1,1 | cut -f2- -d' '
+@end example
+
 @item
 Shuffle a list of directories, but preserve the order of files within
 each directory.  For instance, one could use this to generate a music