xref: /freebsd/usr.bin/cut/cut.1 (revision 6b13d60bf49ee40626d7e3a5d5a80519f0067307)
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.Dd November 6, 2022
32.Dt CUT 1
33.Os
34.Sh NAME
35.Nm cut
36.Nd cut out selected portions of each line of a file
37.Sh SYNOPSIS
38.Nm
39.Fl b Ar list
40.Op Fl n
41.Op Ar
42.Nm
43.Fl c Ar list
44.Op Ar
45.Nm
46.Fl f Ar list
47.Op Fl w | Fl d Ar delim
48.Op Fl s
49.Op Ar
50.Sh DESCRIPTION
51The
52.Nm
53utility cuts out selected portions of each line (as specified by
54.Ar list )
55from each
56.Ar file
57and writes them to the standard output.
58If no
59.Ar file
60arguments are specified, or a file argument is a single dash
61.Pq Sq Fl ,
62.Nm
63reads from the standard input.
64The items specified by
65.Ar list
66can be in terms of column position or in terms of fields delimited
67by a special character.
68Column and field numbering start from 1.
69.Pp
70The
71.Ar list
72option argument
73is a comma or whitespace separated set of increasing numbers and/or
74number ranges.
75Number ranges consist of a number, a dash
76.Pq Sq \- ,
77and a second number
78and select the columns or fields from the first number to the second,
79inclusive.
80Numbers or number ranges may be preceded by a dash, which selects all
81columns or fields from 1 to the last number.
82Numbers or number ranges may be followed by a dash, which selects all
83columns or fields from the last number to the end of the line.
84Numbers and number ranges may be repeated, overlapping, and in any order.
85It is not an error to select columns or fields not present in the
86input line.
87.Pp
88The options are as follows:
89.Bl -tag -width indent
90.It Fl b Ar list
91The
92.Ar list
93specifies byte positions.
94.It Fl c Ar list
95The
96.Ar list
97specifies character positions.
98.It Fl d Ar delim
99Use
100.Ar delim
101as the field delimiter character instead of the tab character.
102.It Fl f Ar list
103The
104.Ar list
105specifies fields, separated in the input by the field delimiter character
106(see the
107.Fl d
108option).
109Output fields are separated by a single occurrence of the field delimiter
110character.
111.It Fl n
112Do not split multi-byte characters.
113Characters will only be output if at least one byte is selected, and,
114after a prefix of zero or more unselected bytes, the rest of the bytes
115that form the character are selected.
116.It Fl s
117Suppress lines with no field delimiter characters.
118Unless specified, lines with no delimiters are passed through unmodified.
119.It Fl w
120Use whitespace (spaces and tabs) as the delimiter.
121Consecutive spaces and tabs count as one single field separator.
122.El
123.Sh ENVIRONMENT
124The
125.Ev LANG , LC_ALL
126and
127.Ev LC_CTYPE
128environment variables affect the execution of
129.Nm
130as described in
131.Xr environ 7 .
132.Sh EXIT STATUS
133.Ex -std
134.Sh EXAMPLES
135Extract users' login names and shells from the system
136.Xr passwd 5
137file as
138.Dq name:shell
139pairs:
140.Pp
141.Dl "cut -d : -f 1,7 /etc/passwd"
142.Pp
143Show the names and login times of the currently logged in users:
144.Pp
145.Dl "who | cut -c 1-16,26-38"
146.Sh SEE ALSO
147.Xr colrm 1 ,
148.Xr paste 1
149.Sh STANDARDS
150The
151.Nm
152utility conforms to
153.St -p1003.2-92 .
154.Pp
155The
156.Fl w
157flag is an extension to the specification.
158.Sh HISTORY
159A
160.Nm
161command first appeared in
162.Bx 4.3 Reno .
163.Sh AUTHORS
164.An -nosplit
165The original Bell Labs version was written by
166.An Gottfried W. R. Luderer
167and the
168.Bx
169version by
170.An Adam S. Moskowitz .
171