coreutils: cut invocation
1
1 8.1 ‘cut’: Print selected parts of lines
1 ========================================
1
1 ‘cut’ writes to standard output selected parts of each line of each
1 input file, or standard input if no files are given or for a file name
1 of ‘-’. Synopsis:
1
1 cut OPTION... [FILE]...
1
1 In the table which follows, the BYTE-LIST, CHARACTER-LIST, and
1 FIELD-LIST are one or more numbers or ranges (two numbers separated by a
1 dash) separated by commas. Bytes, characters, and fields are numbered
1 starting at 1. Incomplete ranges may be given: ‘-M’ means ‘1-M’; ‘N-’
1 means ‘N’ through end of line or last field. The list elements can be
1 repeated, can overlap, and can be specified in any order; but the
1 selected input is written in the same order that it is read, and is
1 written exactly once.
1
11 The program accepts the following options. Also see ⇒Common
options.
1
1 ‘-b BYTE-LIST’
1 ‘--bytes=BYTE-LIST’
1 Select for printing only the bytes in positions listed in
1 BYTE-LIST. Tabs and backspaces are treated like any other
1 character; they take up 1 byte. If an output delimiter is
1 specified, (see the description of ‘--output-delimiter’), then
1 output that string between ranges of selected bytes.
1
1 ‘-c CHARACTER-LIST’
1 ‘--characters=CHARACTER-LIST’
1 Select for printing only the characters in positions listed in
1 CHARACTER-LIST. The same as ‘-b’ for now, but internationalization
1 will change that. Tabs and backspaces are treated like any other
1 character; they take up 1 character. If an output delimiter is
1 specified, (see the description of ‘--output-delimiter’), then
1 output that string between ranges of selected bytes.
1
1 ‘-f FIELD-LIST’
1 ‘--fields=FIELD-LIST’
1 Select for printing only the fields listed in FIELD-LIST. Fields
1 are separated by a TAB character by default. Also print any line
1 that contains no delimiter character, unless the ‘--only-delimited’
1 (‘-s’) option is specified.
1
1 Note ‘awk’ supports more sophisticated field processing, like
1 reordering fields, and handling fields aligned with blank
1 characters. By default ‘awk’ uses (and discards) runs of blank
1 characters to separate fields, and ignores leading and trailing
1 blanks.
1 awk '{print $2}' # print the second field
1 awk '{print $(NF-1)}' # print the penultimate field
1 awk '{print $2,$1}' # reorder the first two fields
1 Note while ‘cut’ accepts field specifications in arbitrary order,
1 output is always in the order encountered in the file.
1
1 In the unlikely event that ‘awk’ is unavailable, one can use the
1 ‘join’ command, to process blank characters as ‘awk’ does above.
1 join -a1 -o 1.2 - /dev/null # print the second field
1 join -a1 -o 1.2,1.1 - /dev/null # reorder the first two fields
1
1 ‘-d INPUT_DELIM_BYTE’
1 ‘--delimiter=INPUT_DELIM_BYTE’
1 With ‘-f’, use the first byte of INPUT_DELIM_BYTE as the input
1 fields separator (default is TAB).
1
1 ‘-n’
1 Do not split multi-byte characters (no-op for now).
1
1 ‘-s’
1 ‘--only-delimited’
1 For ‘-f’, do not print lines that do not contain the field
1 separator character. Normally, any line without a field separator
1 is printed verbatim.
1
1 ‘--output-delimiter=OUTPUT_DELIM_STRING’
1 With ‘-f’, output fields are separated by OUTPUT_DELIM_STRING. The
1 default with ‘-f’ is to use the input delimiter. When using ‘-b’
1 or ‘-c’ to select ranges of byte or character offsets (as opposed
1 to ranges of fields), output OUTPUT_DELIM_STRING between
1 non-overlapping ranges of selected bytes.
1
1 ‘--complement’
1 This option is a GNU extension. Select for printing the complement
1 of the bytes, characters or fields selected with the ‘-b’, ‘-c’ or
1 ‘-f’ options. In other words, do _not_ print the bytes, characters
1 or fields specified via those options. This option is useful when
1 you have many fields and want to print all but a few of them.
1
1 ‘-z’
1 ‘--zero-terminated’
1 Delimit items with a zero byte rather than a newline (ASCII LF).
1 I.e., treat input as items separated by ASCII NUL and terminate
1 output items with ASCII NUL. This option can be useful in
1 conjunction with ‘perl -0’ or ‘find -print0’ and ‘xargs -0’ which
1 do the same in order to reliably handle arbitrary file names (even
1 those containing blanks or other special characters).
1
1 An exit status of zero indicates success, and a nonzero value
1 indicates failure.
1