From: Pádraig Brady
Date: Fri, 24 Jul 2009 23:46:12 +0000 (+0100) Subject: doc: add a sort by line length example X-Git-Tag: v7.5~51 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2f4188ebec8a5cd833dc8061b714145a58dc86aa;p=thirdparty%2Fcoreutils.git doc: add a sort by line length example * doc/coreutils.texi (sort invocation): Add an example showing how to sort data not directly supported by the sort command. --- diff --git a/doc/coreutils.texi b/doc/coreutils.texi index 334d932de1..a804adb5b9 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -4257,6 +4257,17 @@ by the sort operation. @c printf 'c\n\nb\n\na\n'|perl -0pe 's/\n\n/\n\0/g'|sort -z|perl -0pe 's/\0/\n/g' @c @end example +@item +Use the common @acronym{DSU, Decorate Sort Undecorate} idiom to +sort lines according to their length. + +@example +awk '@{print length, $0@}' /etc/passwd | 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 Shuffle a list of directories, but preserve the order of files within each directory. For instance, one could use this to generate a music