~nabijaczleweli/voreutils

ref: 58932cecd7b0d91af0436de15456a6e875a968b9 voreutils/man1/cut.1 -rw-r--r-- 6.7 KiB
58932cec — наб autouploader Manpage update by job 786675 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
.\" SPDX-License-Identifier: 0BSD
.\"
.Dd June 23, 2022
.ds doc-volume-operating-system
.Dt CUT 1
.Os voreutils pre-v0.0.0-latest
.
.Sh NAME
.Nm cut
.Nd extract bytes, characters, or fields
.Sh SYNOPSIS
.Nm
.Fl b Ar range Ns Oo , Ns Ar range Oc Ns 
.Op Fl Czn
.Oo Ar file Oc Ns 
.Nm
.Fl c Ar range Ns Oo , Ns Ar range Oc Ns 
.Op Fl Cz
.Oo Ar file Oc Ns 
.Nm
.Fl f Ar range Ns Oo , Ns Ar range Oc Ns 
.Op Fl Czs
.Op Fl d Ar elimiter
.Op Fl O Ar out-delimiter
.Oo Ar file Oc Ns 
.
.Sh DESCRIPTION
Copies bytes, characters, or fields specified by
.Ar range Ns s
from each line of the input
.Ar file Ns s Pq standard input stream if Qo Sy - Qc , the default ,
to the standard output stream.
.Pp
.Ar range Ns s
can be separated by commas or spaces, and each can be in the format:
.Bl -tag -compact -offset Ds -width ".Ar from Ns Cm - Ns Ar to"
.It Ar number
.Brq Ar number
.It Ar from Ns Cm -
.Ar [ from , No \[if] )
.It Ar from Ns Cm - Ns Ar to
.Ar [ from , to ]
.It Li "\ \ \ \ " Ns Cm - Ns Ar to
.Li [ 1 , Ar to ]
.El
Indices are
.Em 1 Ns -based ,
and a union is taken of all
.Ar range Ns s .
Empty
.Ar range Ns s Pq Ar from No < Ar to
are invalid.
.\" GNU coreutils-compatible
.Pp
With
.Fl b ,
bytes are extracted; with
.Fl n ,
characters are never interrupted mid-sequence, with rounding preferred down
.Pq see Sx EXAMPLES .
With complementary
.Ar range Ns s Pq like Ar -20 No and Ar 21- ,
each character is guaranteed to only be output once.
.Pp
With
.Fl c ,
characters in the current locale are extracted, and invalid sequences are ignored.
.Pp
With
.Fl f ,
.Fl d Ns -delimited
fields are extracted.
If more than one field is matched in a line, they are merged with
.Fl O .
Lines that don't contain a delimiter are passed through verbatim, unless
.Fl s ,
in which case they're removed.
.Pp
The newline
.Pq NUL with Fl z
is never matched and always printed
.Pq unless the entire line was removed with Fl fs .
.
.Sh OPTIONS
.Bl -tag -compact -width ".Fl O , -output-delimiter Ns = Ns Ar out-delim"
.It Fl b , -bytes Ns = Ns Ar range Ns Oo , Ns Ar range Oc Ns 
Extract bytes.
.It Fl n
Don't interrupt multi-byte character sequences.
.Pp
.
.It Fl c , -characters Ns = Ns Ar range Ns Oo , Ns Ar range Oc Ns 
Extract characters in the current locale.
.Pp
.
.It Fl f , -fields Ns = Ns Ar range Ns Oo , Ns Ar range Oc Ns 
Extract delimited fields.
.It Fl d , -delimiter Ns = Ns Ar delim
Split fields on
.Ar delim .
Default: tab.
.It Fl O , -output-delimiter Ns = Ns Ar out-delim
When merging fields for output, use
.Ar out-delim .
Default:
.Ar delim .
.It Fl s , -only-delimited
Remove lines that don't contain
.Ar delim
instead of passing them through.
.Pp
.
.It Fl C , -complement
Invert
.Ar range Ns s :
select all
.Em but
what they match
.Pq \&[ Ns Sy 1 , No \[if] ) \- \[*S] Ns Ar range .
.\" TODO?: this should be a Big Union, but, well
For the purposes of
.Fl n ,
the most minimal set of
.Ar range Ns s
is constructed.
.It Fl z , -zero-terminated
Line separator is NUL, not newline.
.El
.
.Sh EXIT STATUS
.Sy 1
if a
.Ar file
couldn't be opened.
.
.Sh EXAMPLES
.Bd -literal -compact
.Li $ Nm printf Li '\ex01\ex02\ex03\ex04\e0\ex05\ex06\ex07' \&| Nm Fl zb Ar 1,3- Li \&| Nm hexdump Fl C
00000000  01 03 04 00 05 07 00                              |.......|
00000007

.\" TODO: should this have the continued > prompts or just rely on indent?
.Li $ Ic for Ar i Ic in Li $( Ns Nm seq Ar 10 Ns Li ); Ic do
.Li > " " Nm echo Li \&"-$i;$((i+1))-" \&| Nm paste Pa - Li \e
.Li > "   " <( Ns Nm printf Li 'яйцо\enЯЙЦО' \&| Nm cut Fl nb Ar -$i Ns Li )\& \e
.Li > "   " <( Ns Nm printf Li 'яйцо\enЯЙЦО' \&| Nm cut Fl nb Ar $((i+1))- Ns Li )\&
.Li > Ic done
-1;2-           яйцо
                ЯЙЦО
-2;3-   я       йцо
        Я       ЙЦО
-3;4-   я       йцо
        Я       ЙЦО
-4;5-   яй      цо
        ЯЙ      ЦО
-5;6-   яй      цо
        ЯЙ      ЦО
-6;7-   яйц     о
        ЯЙЦ     О
-7;8-   яйц     о
        ЯЙЦ     О
-8;9-   яйцо
        ЯЙЦО
-9;10-  яйцо
        ЯЙЦО
-10;11- яйцо
        ЯЙЦО
.Ed
.Pp
.Bd -literal -compact
.Li $ Nm printf Li 'яйцо\enЯЙЦО' \&| Nm Fl c Ar 1,3-
яцо
ЯЦО
.Ed
.Pp
.Bd -literal -compact
# name, IDs, homedir, shell, ...
.Li $ Nm Fl f Ar 1,3-4,6- Fl d Ns Ar \&: Fl O Ns Li \&"$( Ns Nm printf Li '\et')" Pa /etc/passwd
root    0       0       /root   /bin/bash
bin     2       2       /bin    /usr/sbin/nologin
irc     39      39      /var/run/ircd   /usr/sbin/nologin
cicada  1000    100     /home/cicada    /bin/bash
nobody  65534   65534   /nonexistent    /usr/sbin/nologin
# Everything else: password and GNATS
.Li $ Nm Fl Cf Ar 1,3-4,6- Fl d Ns Ar \&: Fl O Ns Li \&"$( Ns Nm printf Li '\et')" Pa /etc/passwd
x       root
x       bin
x       ircd
x       Cicadum,,,
x       nobody
.Ed
.
.Sh SEE ALSO
.Xr paste 1 ,
.Xr mbrlen 3
.
.Sh STANDARDS
Conforms to
.St -p1003.1-2008 ;
.Fl CzO
are extensions, compatible with the GNU system
.Pq the short versions of Fl CO No are not available there .
Allowing
.Fl d
longer than one character is an extension \(em some nonconformant implementations only allow a single byte (the GNU system) or only use the first byte of the
.Ar delim Pq Nx , Ox .
.Pp
Тhis implementation allows all formats allowed by
.Xr strtoull 3
in
.Ar range Ns s ,
but some others
.Pq the Bx , the GNU system
only allow decimal digits.
.
.Sh HISTORY
.\" Copied from CB-UNIX man1/02/p57; matches SysIII
.\" cf. paste.1
Written by Gottfried W. R. Luderer with the corresponding
.Xr paste 1 ,
appeared mostly-fully-formed in
.Tn CB-UNIX
at or before 2.1 as
.Xr cut 1 :
.D1 cut \- cut out selected fields of each line of a file
.\" Sy "cut  \-c" Ns "list [file1  file2  ...]"
.\" Sy "cut  \-f" Ns "list [" Ns Sy \-d Ns "char] [" Ns Sy \-s Ns "] [file1  file2  ...]"
Supporting
.Fl c
and
.Fl fds ,
with
.Fl c
handling a single
.Tn ASCII
backspace
.Pq Sy 0x08
"as produced by nroff" by not considering it and the next character as being in the position of the previous one
.Pq i.e. Cm printf Li 'abc\ebdef\ebgh\en' \&| Nm Fl c Ns Ar 3 No is So Li c\ebd Sc , Li \&| Nm Fl c Ns Ar 4 No is So Li e Sc , &c.\& .
.Fl c
is equivalent, with the single-byte characters of then, to today's
.Fl b .
It also notes that the
.Ar range Ns s
are
.Qq as in the Fl o No option to Em nroff Ns / Ns Em troff No for page ranges .
.Tn CB-UNIX
was, among others, the basis for
.At III ,
where it first saw light outside of AT&T.
.Pp
A bug in
.At V.2 ,
caused by a transition to reading in blocks, breaks the backspace behaviour.
.Pp
.At V.3
fixes that, and allows
.Qq Sy -
as
.Ar file
to mean the standard input stream.
.Pp
.St -p1003.2-92
created
.Fl b
and
.Fl n ,
as part of support for multi-byte character encodings.
.Pp
A
.Tn CB-UNIX Ns -compatible
.Nm
appears in
.Bx 4.3 Reno .