NAME
cut — cut out (extract) selected fields of each line of a file
SYNOPSIS
cut -c
list
[file]...
cut -b
list
[-n]
[file]...
cut -f
list
[-d
char]
[-s]
[file]...
DESCRIPTION
cut
cuts out (extracts) columns from a table
or fields from each line in a file;
in data base parlance, it implements the projection of a relation.
Fields as specified by
list
can be fixed length
(defined in terms of character or byte position in a line
when using the
-c
or
-b
option), or the length can vary from line to line
and be marked with a field delimiter character such as
the tab character (when using the
-f
option).
cut
can be used as a filter;
if no files are given, the standard input is used.
When processing single-byte character sets, the
-c
and
-b
options are equivalent and produce identical results.
When processing multi-byte character sets,
when the
-b
and
-n
options are used together, their combined behavior is very similar,
but not identical to the
-c
option.
Options
Options are interpreted as follows:
- list
A comma-separated list of integer
byte
(-b
option),
character
(-c
option), or
field
(-f
option) numbers, in increasing order, with optional
-
to indicate ranges.
For example:
- 1,4,7
Positions 1, 4, and 7.
- 1-3,8
Positions 1 through 3 and 8.
- -5,10
Positions 1 through 5 and 10.
- 3-
Position 3 through last position.
- -b list
Cut based on a list of bytes.
Each selected byte is output unless the
-n
option is also specified.
- -c list
Cut based on character positions specified by
list
(-c 1-72
extracts the first 72 characters of each line).
- -f list
Where
list
is a list of fields
assumed to be separated in the file by a delimiter character (see
-d);
for example,
-f 1,7
copies the first and seventh field only.
Lines with no field delimiters will be passed through intact (useful
for table subheadings), unless
-s
is specified.
- -d char
The character following
-d
is the field delimiter
(-f
option only).
Default is
tab.
Space or other characters with special meaning to the shell must be quoted.
Adjacent field delimiters delimit null fields.
char
may be an international code set character.
- -n
Do not split characters.
If the high end of a range within a list
is not the last byte of a character,
that character is not included in the output.
However, if the low end of a range within a list
is not the first byte of a character,
the entire character
is
included in the output."
- -s
Suppresses lines with no delimiter characters when using
-f
option.
Unless
-s
is specified,
lines with no delimiters appear in the output without alteration.
Hints
Use
grep
to extract text from a file based on text pattern recognition
(using regular expressions).
Use
paste
to merge files line-by-line in columnar format.
To rearrange columns in a table in a different sequence, use
cut
and
paste.
See
grep(1)
and
paste(1)
for more information.
EXTERNAL INFLUENCES
Environment Variables
LC_CTYPE
determines the interpretation of text as single and/or
multi-byte characters.
If
LC_CTYPE
is not specified in the environment or is set to
the empty string, the value of
LANG
is used as a default for each
unspecified or empty variable. If
LANG
is not specified or is set to the empty string,
a default of "C" (see
lang(5))
is
used instead of
LANG.
If any internationalization variable contains an invalid setting,
cut
behaves as if all internationalization variables are set to "C".
See
environ(5).
International Code Set Support
cut
supports both single- and multi-byte character code sets.
International code set characters may be specified
in the
char
given to the
-d
option.
cut
recognizes the international code
set characters
according to the locale specified in the
LC_CTYPE
environment variable.
EXAMPLES
Password file mapping of user ID to user names:
cut -d : -f 1,5 /etc/passwd
Set environment variable
name
to current login name:
name=`who am i | cut -f 1 -d " "`
Convert file
source
containing lines of arbitrary length into two files where
file1
contains the first 500 bytes
(unless the 500th byte is within a multi-byte character),
and
file2
contains the remainder of each line:
cut -b 1-500 -n source > file1
cut -b 500- -n source > file2
DIAGNOSTICS
- line too long
Line length must not exceed
LINE_MAX
characters or fields, including the new-line character (see
limits(5).
- bad list for b/c/f option
Missing
-b,
-c,
or
-f
option or incorrectly specified
list.
No error occurs if a line has fewer fields than the
list
calls for.
- no fields
list
is empty.
WARNINGS
cut
does not expand tabs.
Pipe text through
expand(1)
if tab expansion is required.
Backspace characters are treated the same as any other character.
To eliminate backspace characters before processing by
cut,
use the
fold
or
col
command (see
fold(1)
and
col(1)).
AUTHOR
cut
was developed by OSF and HP.
STANDARDS CONFORMANCE
cut: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2