cut(1) cut(1)
NAME
cut - cut out selected fields of each line of a file
SYNOPSIS
cut -b list [-n] [--] [file ...] Format 1a
cut -c list [--] [file ...] Format 1b
cut -f list [-d char] [-s] [--] [file ...] Format 2
DESCRIPTION
cut reads an input text from files or from standard input one line at
a time and cuts out specific columns (Format 1) or fields (Format 2)
from these lines. The selected columns or fields are written to stan-
dard output.
OPTIONS
Format 1: Cutting out columns
cut -b list [-n] [--] [file ...]
cut -c list [--] [file ...]
-b list
(byte) cut cuts out the columns specified in list from each input
line and writes them to standard output. A column is exactly one
byte wide.
list is a list of numbers or a range. The individual elements in
the list must be separated by commas and arranged in ascending
order. A range of columns given as n1-n2 includes all numbers
from n1 up to, and including, n2.
The following abbreviations are permissible in range definitions:
-n for 1 - n
n- for n - "last column"
Example:
1,3,5 cut cuts out columns 1, 3, and 5.
1-3,5 cut cuts out columns 1, 2, 3, and 5.
-3,5 is the abbreviation for 1 - 3, and 5.
3- is the abbreviation for 3 - "last column".
-n Characters comprising a number of bytes are not split. The upper
and lower range definition limits are reduced internally until
the range includes only complete characters.
Page 1 Reliant UNIX 5.44 Printed 11/98
cut(1) cut(1)
-c list
(column) The columns specified in list are cut out from each
input line and written to standard output. A column is exactly
one character wide.
list is list of numbers or number ranges, as described for the -b
option.
-- If file begins with a dash (-), the end of the command-line
options must be marked with --.
file Name of the input file.
You may name more than one file.
file not specified: cut reads from standard input.
Format 2: Cutting out fields
cut -f list [-d char] [-s] [--] [file ...]
-f list
(field) cut cuts out the fields specified in list from each input
line and writes them on standard output.
A field comprises all characters that are located between two
field delimiters. Two successive field delimiters mark an empty
field. The field delimiter defaults to the tab character, but you
can redefine it in the -d option.
The output fields are separated from one another by one field
delimiter each. Input lines with no field delimiters are output
in full (unless the -s option is set). This is generally useful
for table subheadings.
list is specified as described under Format 1.
-d char
The character given as char serves as the field delimiter.
If char is a blank or a shell metacharacter [see specialchar(5)]
it must be enclosed in single quotes: -d 'char'.
-d not specified:
The field delimiter defaults to the tab character.
-s Lines with no field delimiters are suppressed.
-s not specified:
Lines with no field delimiters are output in full.
Page 2 Reliant UNIX 5.44 Printed 11/98
cut(1) cut(1)
-- If file begins with a dash (-), the end of the command-line
options must be marked with --.
file Name of the input file.
You may name more than one file.
file not specified: cut reads from standard input.
ERROR MESSAGES
ERROR: line too long
A line can have no more than 1023 characters or fields. Alternatively,
the newline character may be missing.
ERROR: bad list for c/f option
Missing -c or -f option or incorrectly specified list. No error is
reported if a line has fewer fields than required for the list.
ERROR: no fields
The list is empty.
ERROR: no delimiter
The delimiter character missing from the -d option.
ERROR: cannot handle multiple adjacent backspaces
Adjacent backspaces cannot be processed correctly.
WARNING: cannot open file
The named file cannot be read or does not exist. If multiple files
have been specified, processing will continue on the other files.
LOCALE
The LCMESSAGES environment variable governs the language in which
message texts are displayed. If LCMESSAGES is undefined or is defined
as the null string, it defaults to the value of LANG. If LANG is like-
wise undefined or null, the system acts as if it were not internation-
alized.
The LCALL environment variable governs the entire locale. LCALL
takes precedence over all the other environment variables which affect
internationalization.
Page 3 Reliant UNIX 5.44 Printed 11/98
cut(1) cut(1)
EXAMPLES
Example 1
Print the first 72 characters of each input line:
$ cut -c 1-72 file
Example 2
Output the first 72 bytes of each input line under the condition that
multi-byte characters are not split:
cut -b 1-71 -n file
Example 3
The first and third fields of the /etc/passwd file (i.e. the login
name and user ID) are cut out and output. The individual fields in
this file are separated by means of a colon.
$ cut -f 1,3 -d: /etc/passwd
Example 4
The names of customers whose bills are due on the first day of any
month are to be filtered out of the invoice file of a mail order house
along with the amount due from each of them.
The file is structured as follows:
Homewood Milwaukee 10,000 06.01.91
Mackenzie Detroit 7,000 07.06.91
Macnamara Boston 8,000 05.01.91
Tinniswood Atlanta 450 06.20.91
The fields in the table are separated by exactly one tab and padded
with blanks.
$ grep '\.01\.91' invoice | cut -f 1,3 > names
$ cat names
Homewood 10,000
Macnamara 8,000
Explanation: grep finds all lines containing the string .01.91 and
writes them to standard output. cut receives these lines as input,
selects the first and third fields, and writes its output to the file
names.
If you would then like each customer name in the names file to be pre-
ceded by the date and then sorted accordingly, you could enter:
$ grep '\.01\.91' invoice | cut -f 4 > date
Page 4 Reliant UNIX 5.44 Printed 11/98
cut(1) cut(1)
$ paste date names | sort
05.01.91 Macnamara 8,000
06.01.91 Homewood 10,000
Explanation: The first command line writes the date associated with
the selected customer names to the file named date. The paste command
pastes the lines in the date and names files horizontally, separating
them with the default tab character. The sort command then sorts the
output lines in ascending order of date.
SEE ALSO
awk(1), grep(1), paste(1), sh(1).
Page 5 Reliant UNIX 5.44 Printed 11/98