summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2010-11-24 08:37:23 +0000
committerPádraig Brady <P@draigBrady.com>2011-01-29 23:48:36 +0000
commit38cdb01a32ba386a42c370be8371a8bf884eacce (patch)
tree9643624f7823981b14a88e748ee54f6230c0e9bf
parent877ca5bf8588ae73a6ccc672e41f13c5b3943b14 (diff)
downloadcoreutils-38cdb01a32ba386a42c370be8371a8bf884eacce.tar.xz
doc: add alternatives for field processing not supported by cut
* doc/coreutils.texi (cut invocation): Remove the tr -s '[:blank:]' example, as it doesn't handle leading and trailing blanks. Add `awk` examples for common field processing operations often asked about. Also document a `join` hack, to achieve the same thing. Note the join options are ordered so as to be compatible with other systems.
-rw-r--r--doc/coreutils.texi23
1 files changed, 19 insertions, 4 deletions
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index b89147ea8..ea35afe29 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -5506,11 +5506,26 @@ Select for printing only the fields listed in @var{field-list}.
Fields are separated by a TAB character by default. Also print any
line that contains no delimiter character, unless the
@option{--only-delimited} (@option{-s}) option is specified.
-Note @command{cut} does not support specifying runs of whitespace as a
-delimiter, so to achieve that common functionality one can pre-process
-with @command{tr} like:
+
+Note @command{awk} supports more sophisticated field processing,
+and by default will use (and discard) runs of blank characters to
+separate fields, and ignore leading and trailing blanks.
+@example
+@verbatim
+awk '{print $2}' # print the second field
+awk '{print $NF-1}' # print the penultimate field
+awk '{print $2,$1}' # reorder the first two fields
+@end verbatim
+@end example
+
+In the unlikely event that @command{awk} is unavailable,
+one can use the @command{join} command, to process blank
+characters as @command{awk} does above.
@example
-tr -s '[:blank:]' '\t' | cut -f@dots{}
+@verbatim
+join -a1 -o 1.2 - /dev/null # print the second field
+join -a1 -o 1.2,1.1 - /dev/null # reorder the first two fields
+@end verbatim
@end example
@item -d @var{input_delim_byte}