From: Pádraig Brady
Date: Tue, 23 Apr 2024 11:58:17 +0000 (+0100) Subject: doc: sort: give example for sorting on the last field X-Git-Tag: v9.6~249 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=adb6338bb5cd01f4b733a96354fa6775741224e9;p=thirdparty%2Fcoreutils.git doc: sort: give example for sorting on the last field * 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 --- diff --git a/doc/coreutils.texi b/doc/coreutils.texi index 2c6c8b68bb..3762c6f96e 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -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