Name
cut
Synopsis
cutoptions
[files
]
Select a list of columns or fields from one or more
files. Either -c
or
-f
must be specified. list
is a sequence of integers. Use a comma between separate values and
a hyphen to specify a range (e.g., 1-10,15,20
or 50-
). See also paste and
join.
Common Options
-b
list
,--bytes
list
This list specifies byte positions, not character positions. This is important when multibyte characters are used. With this option, lines should be 1023 bytes or less in size.
-c
list
,--characters
list
Cut the character positions identified in list.
-d
c
,--delimiter
c
Use with
-f
to specify field delimiter as character c (default is tab); special characters (e.g., a space) must be quoted.-f
list
,--fields
list
Cut the fields identified in list.
-
-n
Do not split characters. When used with
-b
, cut doesn’t split multibyte characters.-s
,--only-delimited
Use with
-f
to suppress lines without delimiters.
GNU/Linux Option
-
--output-delimiter=
string
Use string as the output delimiter. By default, the output delimiter is the same as the input delimiter.
Examples
Extract usernames and real names from /etc/passwd:
cut -d: -f1,5 /etc/passwd
Find out who is logged on, but list only login names:
who | cut -d" " -f1
Cut characters in the fourth column of file, and paste them back as the first column in the same file. Send the results to standard output:
cut -c4file
| paste -file
Get Unix in a Nutshell, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.