xref: /freebsd/usr.bin/cut/cut.1 (revision e5b786625f7f82a1fa91e41823332459ea5550f9)
1.\" Copyright (c) 1989, 1990, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" the Institute of Electrical and Electronics Engineers, Inc.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the University nor the names of its contributors
16.\"    may be used to endorse or promote products derived from this software
17.\"    without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.\"     @(#)cut.1	8.1 (Berkeley) 6/6/93
32.\"
33.Dd November 6, 2022
34.Dt CUT 1
35.Os
36.Sh NAME
37.Nm cut
38.Nd cut out selected portions of each line of a file
39.Sh SYNOPSIS
40.Nm
41.Fl b Ar list
42.Op Fl n
43.Op Ar
44.Nm
45.Fl c Ar list
46.Op Ar
47.Nm
48.Fl f Ar list
49.Op Fl w | Fl d Ar delim
50.Op Fl s
51.Op Ar
52.Sh DESCRIPTION
53The
54.Nm
55utility cuts out selected portions of each line (as specified by
56.Ar list )
57from each
58.Ar file
59and writes them to the standard output.
60If no
61.Ar file
62arguments are specified, or a file argument is a single dash
63.Pq Sq Fl ,
64.Nm
65reads from the standard input.
66The items specified by
67.Ar list
68can be in terms of column position or in terms of fields delimited
69by a special character.
70Column and field numbering start from 1.
71.Pp
72The
73.Ar list
74option argument
75is a comma or whitespace separated set of increasing numbers and/or
76number ranges.
77Number ranges consist of a number, a dash
78.Pq Sq \- ,
79and a second number
80and select the columns or fields from the first number to the second,
81inclusive.
82Numbers or number ranges may be preceded by a dash, which selects all
83columns or fields from 1 to the last number.
84Numbers or number ranges may be followed by a dash, which selects all
85columns or fields from the last number to the end of the line.
86Numbers and number ranges may be repeated, overlapping, and in any order.
87It is not an error to select columns or fields not present in the
88input line.
89.Pp
90The options are as follows:
91.Bl -tag -width indent
92.It Fl b Ar list
93The
94.Ar list
95specifies byte positions.
96.It Fl c Ar list
97The
98.Ar list
99specifies character positions.
100.It Fl d Ar delim
101Use
102.Ar delim
103as the field delimiter character instead of the tab character.
104.It Fl f Ar list
105The
106.Ar list
107specifies fields, separated in the input by the field delimiter character
108(see the
109.Fl d
110option).
111Output fields are separated by a single occurrence of the field delimiter
112character.
113.It Fl n
114Do not split multi-byte characters.
115Characters will only be output if at least one byte is selected, and,
116after a prefix of zero or more unselected bytes, the rest of the bytes
117that form the character are selected.
118.It Fl s
119Suppress lines with no field delimiter characters.
120Unless specified, lines with no delimiters are passed through unmodified.
121.It Fl w
122Use whitespace (spaces and tabs) as the delimiter.
123Consecutive spaces and tabs count as one single field separator.
124.El
125.Sh ENVIRONMENT
126The
127.Ev LANG , LC_ALL
128and
129.Ev LC_CTYPE
130environment variables affect the execution of
131.Nm
132as described in
133.Xr environ 7 .
134.Sh EXIT STATUS
135.Ex -std
136.Sh EXAMPLES
137Extract users' login names and shells from the system
138.Xr passwd 5
139file as
140.Dq name:shell
141pairs:
142.Pp
143.Dl "cut -d : -f 1,7 /etc/passwd"
144.Pp
145Show the names and login times of the currently logged in users:
146.Pp
147.Dl "who | cut -c 1-16,26-38"
148.Sh SEE ALSO
149.Xr colrm 1 ,
150.Xr paste 1
151.Sh STANDARDS
152The
153.Nm
154utility conforms to
155.St -p1003.2-92 .
156.Pp
157The
158.Fl w
159flag is an extension to the specification.
160.Sh HISTORY
161A
162.Nm
163command first appeared in
164.Bx 4.3 Reno .
165.Sh AUTHORS
166.An -nosplit
167The original Bell Labs version was written by
168.An Gottfried W. R. Luderer
169and the
170.Bx
171version by
172.An Adam S. Moskowitz .
173