xref: /minix3/usr.bin/sed/sed.1 (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc.\"	$NetBSD: sed.1,v 1.40 2014/06/25 02:05:58 uwe Exp $
2f789fee2SBen Gras.\" Copyright (c) 1992, 1993
3f789fee2SBen Gras.\"	The Regents of the University of California.  All rights reserved.
4f789fee2SBen Gras.\"
5f789fee2SBen Gras.\" This code is derived from software contributed to Berkeley by
6f789fee2SBen Gras.\" the Institute of Electrical and Electronics Engineers, Inc.
7f789fee2SBen Gras.\"
8f789fee2SBen Gras.\" Redistribution and use in source and binary forms, with or without
9f789fee2SBen Gras.\" modification, are permitted provided that the following conditions
10f789fee2SBen Gras.\" are met:
11f789fee2SBen Gras.\" 1. Redistributions of source code must retain the above copyright
12f789fee2SBen Gras.\"    notice, this list of conditions and the following disclaimer.
13f789fee2SBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright
14f789fee2SBen Gras.\"    notice, this list of conditions and the following disclaimer in the
15f789fee2SBen Gras.\"    documentation and/or other materials provided with the distribution.
16f789fee2SBen Gras.\" 3. Neither the name of the University nor the names of its contributors
17f789fee2SBen Gras.\"    may be used to endorse or promote products derived from this software
18f789fee2SBen Gras.\"    without specific prior written permission.
19f789fee2SBen Gras.\"
20f789fee2SBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21f789fee2SBen Gras.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22f789fee2SBen Gras.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23f789fee2SBen Gras.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24f789fee2SBen Gras.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25f789fee2SBen Gras.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26f789fee2SBen Gras.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27f789fee2SBen Gras.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28f789fee2SBen Gras.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29f789fee2SBen Gras.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30f789fee2SBen Gras.\" SUCH DAMAGE.
31f789fee2SBen Gras.\"
32f789fee2SBen Gras.\"	@(#)sed.1	8.2 (Berkeley) 12/30/93
33*0a6a1f1dSLionel Sambuc.\" $FreeBSD: head/usr.bin/sed/sed.1 259132 2013-12-09 18:57:20Z eadler $
34f789fee2SBen Gras.\"
35*0a6a1f1dSLionel Sambuc.Dd June 18, 2014
36f789fee2SBen Gras.Dt SED 1
37f789fee2SBen Gras.Os
38f789fee2SBen Gras.Sh NAME
39f789fee2SBen Gras.Nm sed
40f789fee2SBen Gras.Nd stream editor
41f789fee2SBen Gras.Sh SYNOPSIS
42f789fee2SBen Gras.Nm
43*0a6a1f1dSLionel Sambuc.Op Fl aElnru
44f789fee2SBen Gras.Ar command
45*0a6a1f1dSLionel Sambuc.Op Ar
46f789fee2SBen Gras.Nm
47*0a6a1f1dSLionel Sambuc.Op Fl aElnru
48f789fee2SBen Gras.Op Fl e Ar command
49f789fee2SBen Gras.Op Fl f Ar command_file
50*0a6a1f1dSLionel Sambuc.Op Fl I Ns Op Ar extension
51*0a6a1f1dSLionel Sambuc.Op Fl i Ns Op Ar extension
52*0a6a1f1dSLionel Sambuc.Op Ar
53f789fee2SBen Gras.Sh DESCRIPTION
54f789fee2SBen GrasThe
55f789fee2SBen Gras.Nm
56f789fee2SBen Grasutility reads the specified files, or the standard input if no files
57f789fee2SBen Grasare specified, modifying the input as specified by a list of commands.
58f789fee2SBen GrasThe input is then written to the standard output.
59f789fee2SBen Gras.Pp
60f789fee2SBen GrasA single command may be specified as the first argument to
61f789fee2SBen Gras.Nm .
62f789fee2SBen GrasMultiple commands may be specified by using the
63f789fee2SBen Gras.Fl e
64f789fee2SBen Grasor
65f789fee2SBen Gras.Fl f
66f789fee2SBen Grasoptions.
67f789fee2SBen GrasAll commands are applied to the input in the order they are specified
68f789fee2SBen Grasregardless of their origin.
69f789fee2SBen Gras.Pp
70f789fee2SBen GrasThe following options are available:
71f789fee2SBen Gras.Bl -tag -width indent
72f789fee2SBen Gras.It Fl a
73f789fee2SBen GrasThe files listed as parameters for the
74f789fee2SBen Gras.Dq w
75f789fee2SBen Grasfunctions are created (or truncated) before any processing begins,
76f789fee2SBen Grasby default.
77f789fee2SBen GrasThe
78f789fee2SBen Gras.Fl a
79f789fee2SBen Grasoption causes
80f789fee2SBen Gras.Nm
81f789fee2SBen Grasto delay opening each file until a command containing the related
82f789fee2SBen Gras.Dq w
83f789fee2SBen Grasfunction is applied to a line of input.
84f789fee2SBen Gras.It Fl E
85*0a6a1f1dSLionel SambucInterpret regular expressions as extended (modern) regular expressions
86*0a6a1f1dSLionel Sambucrather than basic regular expressions (BRE's).
87*0a6a1f1dSLionel SambucThe
88*0a6a1f1dSLionel Sambuc.Xr re_format 7
89*0a6a1f1dSLionel Sambucmanual page fully describes both formats.
90f789fee2SBen Gras.It Fl e Ar command
91f789fee2SBen GrasAppend the editing commands specified by the
92f789fee2SBen Gras.Ar command
93f789fee2SBen Grasargument
94f789fee2SBen Grasto the list of commands.
95f789fee2SBen Gras.It Fl f Ar command_file
96f789fee2SBen GrasAppend the editing commands found in the file
97f789fee2SBen Gras.Ar command_file
98f789fee2SBen Grasto the list of commands.
99f789fee2SBen GrasThe editing commands should each be listed on a separate line.
100*0a6a1f1dSLionel Sambuc.It Fl I Ns Op Ar extension
101*0a6a1f1dSLionel SambucEdit files in-place, saving backups with the specified
102*0a6a1f1dSLionel Sambuc.Ar extension .
103*0a6a1f1dSLionel SambucIf no
104*0a6a1f1dSLionel Sambuc.Ar extension
105*0a6a1f1dSLionel Sambucis given, no backup will be saved.
106*0a6a1f1dSLionel SambucIt is not recommended to give a zero-length
107*0a6a1f1dSLionel Sambuc.Ar extension
108*0a6a1f1dSLionel Sambucwhen in-place editing files, as you risk corruption or partial content
109*0a6a1f1dSLionel Sambucin situations where disk space is exhausted, etc.
110*0a6a1f1dSLionel Sambuc.Pp
111*0a6a1f1dSLionel SambucNote that in-place editing with
112*0a6a1f1dSLionel Sambuc.Fl I
113*0a6a1f1dSLionel Sambucstill takes place in a single continuous line address space covering
114*0a6a1f1dSLionel Sambucall files, although each file preserves its individuality instead of
115*0a6a1f1dSLionel Sambucforming one output stream.
116*0a6a1f1dSLionel SambucThe line counter is never reset between files, address ranges can span
117*0a6a1f1dSLionel Sambucfile boundaries, and the
118*0a6a1f1dSLionel Sambuc.Dq $
119*0a6a1f1dSLionel Sambucaddress matches only the last line of the last file.
120*0a6a1f1dSLionel Sambuc(See
121*0a6a1f1dSLionel Sambuc.Sx "Sed Addresses" . )
122*0a6a1f1dSLionel SambucThat can lead to unexpected results in many cases of in-place editing,
123*0a6a1f1dSLionel Sambucwhere using
124*0a6a1f1dSLionel Sambuc.Fl i
125*0a6a1f1dSLionel Sambucis desired.
126*0a6a1f1dSLionel Sambuc.It Fl i Ns Op Ar extension
127*0a6a1f1dSLionel SambucEdit files in-place similarly to
128*0a6a1f1dSLionel Sambuc.Fl I ,
129*0a6a1f1dSLionel Sambucbut treat each file independently from other files.
130*0a6a1f1dSLionel SambucIn particular, line numbers in each file start at 1,
131*0a6a1f1dSLionel Sambucthe
132*0a6a1f1dSLionel Sambuc.Dq $
133*0a6a1f1dSLionel Sambucaddress matches the last line of the current file,
134*0a6a1f1dSLionel Sambucand address ranges are limited to the current file.
135*0a6a1f1dSLionel Sambuc(See
136*0a6a1f1dSLionel Sambuc.Sx "Sed Addresses" . )
137*0a6a1f1dSLionel SambucThe net result is as though each file were edited by a separate
138*0a6a1f1dSLionel Sambuc.Nm
139*0a6a1f1dSLionel Sambucinstance.
140*0a6a1f1dSLionel Sambuc.It Fl l
141*0a6a1f1dSLionel SambucMake output line buffered.
142f789fee2SBen Gras.It Fl n
143f789fee2SBen GrasBy default, each line of input is echoed to the standard output after
144f789fee2SBen Grasall of the commands have been applied to it.
145f789fee2SBen GrasThe
146f789fee2SBen Gras.Fl n
147f789fee2SBen Grasoption suppresses this behavior.
148f789fee2SBen Gras.It Fl r
149*0a6a1f1dSLionel SambucSame as
150*0a6a1f1dSLionel Sambuc.Fl E
151*0a6a1f1dSLionel Sambucfor compatibility with GNU sed.
152*0a6a1f1dSLionel Sambuc.It Fl u
153*0a6a1f1dSLionel SambucMake output unbuffered.
154f789fee2SBen Gras.El
155f789fee2SBen Gras.Pp
156f789fee2SBen GrasThe form of a
157f789fee2SBen Gras.Nm
158f789fee2SBen Grascommand is as follows:
159*0a6a1f1dSLionel Sambuc.Pp
160f789fee2SBen Gras.Dl [address[,address]]function[arguments]
161*0a6a1f1dSLionel Sambuc.Pp
162f789fee2SBen GrasWhitespace may be inserted before the first address and the function
163f789fee2SBen Grasportions of the command.
164f789fee2SBen Gras.Pp
165f789fee2SBen GrasNormally,
166f789fee2SBen Gras.Nm
167f789fee2SBen Grascyclically copies a line of input, not including its terminating newline
168f789fee2SBen Grascharacter, into a
169f789fee2SBen Gras.Em "pattern space" ,
170f789fee2SBen Gras(unless there is something left after a
171f789fee2SBen Gras.Dq D
172f789fee2SBen Grasfunction),
173f789fee2SBen Grasapplies all of the commands with addresses that select that pattern space,
174f789fee2SBen Grascopies the pattern space to the standard output, appending a newline, and
175f789fee2SBen Grasdeletes the pattern space.
176f789fee2SBen Gras.Pp
177f789fee2SBen GrasSome of the functions use a
178f789fee2SBen Gras.Em "hold space"
179f789fee2SBen Grasto save all or part of the pattern space for subsequent retrieval.
180*0a6a1f1dSLionel Sambuc.Ss "Sed Addresses"
181*0a6a1f1dSLionel SambucAn address is not required, but if specified must have one of the
182*0a6a1f1dSLionel Sambucfollowing formats:
183*0a6a1f1dSLionel Sambuc.Bl -bullet -offset indent
184*0a6a1f1dSLionel Sambuc.It
185*0a6a1f1dSLionel Sambuca number that counts
186f789fee2SBen Grasinput lines
187*0a6a1f1dSLionel Sambuccumulatively across input files (or in each file independently
188*0a6a1f1dSLionel Sambucif a
189*0a6a1f1dSLionel Sambuc.Fl i
190*0a6a1f1dSLionel Sambucoption is in effect);
191*0a6a1f1dSLionel Sambuc.It
192*0a6a1f1dSLionel Sambuca dollar
193*0a6a1f1dSLionel Sambuc.Pq Dq $
194*0a6a1f1dSLionel Sambuccharacter that addresses the last line of input (or the last line
195*0a6a1f1dSLionel Sambucof the current file if a
196*0a6a1f1dSLionel Sambuc.Fl i
197*0a6a1f1dSLionel Sambucoption was specified);
198*0a6a1f1dSLionel Sambuc.It
199*0a6a1f1dSLionel Sambuca context address
200*0a6a1f1dSLionel Sambucthat consists of a regular expression preceded and followed by a
201*0a6a1f1dSLionel Sambucdelimiter.
202*0a6a1f1dSLionel SambucThe closing delimiter can also optionally be followed by the
203*0a6a1f1dSLionel Sambuc.Dq i
204*0a6a1f1dSLionel Sambuccharacter, to indicate that the regular expression is to be matched
205*0a6a1f1dSLionel Sambucin a case-insensitive way.
206*0a6a1f1dSLionel Sambuc.El
207f789fee2SBen Gras.Pp
208f789fee2SBen GrasA command line with no addresses selects every pattern space.
209f789fee2SBen Gras.Pp
210f789fee2SBen GrasA command line with one address selects all of the pattern spaces
211f789fee2SBen Grasthat match the address.
212f789fee2SBen Gras.Pp
213*0a6a1f1dSLionel SambucA command line with two addresses selects an inclusive range.
214*0a6a1f1dSLionel SambucThis
215*0a6a1f1dSLionel Sambucrange starts with the first pattern space that matches the first
216*0a6a1f1dSLionel Sambucaddress.
217*0a6a1f1dSLionel SambucThe end of the range is the next following pattern space
218*0a6a1f1dSLionel Sambucthat matches the second address.
219*0a6a1f1dSLionel SambucIf the second address is a number
220*0a6a1f1dSLionel Sambucless than or equal to the line number first selected, only that
221*0a6a1f1dSLionel Sambucline is selected.
222*0a6a1f1dSLionel SambucThe number in the second address may be prefixed with a
223*0a6a1f1dSLionel Sambuc.Pq Dq \&+
224*0a6a1f1dSLionel Sambucto specify the number of lines to match after the first pattern.
225*0a6a1f1dSLionel SambucIn the case when the second address is a context
226*0a6a1f1dSLionel Sambucaddress,
227*0a6a1f1dSLionel Sambuc.Nm
228*0a6a1f1dSLionel Sambucdoes not re-match the second address against the
229*0a6a1f1dSLionel Sambucpattern space that matched the first address.
230*0a6a1f1dSLionel SambucStarting at the
231*0a6a1f1dSLionel Sambucfirst line following the selected range,
232f789fee2SBen Gras.Nm
233f789fee2SBen Grasstarts looking again for the first address.
234f789fee2SBen Gras.Pp
235f789fee2SBen GrasEditing commands can be applied to non-selected pattern spaces by use
236f789fee2SBen Grasof the exclamation character
237f789fee2SBen Gras.Pq Dq \&!
238f789fee2SBen Grasfunction.
239*0a6a1f1dSLionel Sambuc.Ss "Sed Regular Expressions"
240*0a6a1f1dSLionel SambucThe regular expressions used in
241*0a6a1f1dSLionel Sambuc.Nm ,
242*0a6a1f1dSLionel Sambucby default, are basic regular expressions (BREs, see
243f789fee2SBen Gras.Xr re_format 7
244*0a6a1f1dSLionel Sambucfor more information), but extended (modern) regular expressions can be used
245*0a6a1f1dSLionel Sambucinstead if the
246*0a6a1f1dSLionel Sambuc.Fl E
247*0a6a1f1dSLionel Sambucflag is given.
248f789fee2SBen GrasIn addition,
249f789fee2SBen Gras.Nm
250*0a6a1f1dSLionel Sambuchas the following two additions to regular expressions:
251*0a6a1f1dSLionel Sambuc.Pp
252f789fee2SBen Gras.Bl -enum -compact
253f789fee2SBen Gras.It
254f789fee2SBen GrasIn a context address, any character other than a backslash
255*0a6a1f1dSLionel Sambuc.Pq Dq \e
256*0a6a1f1dSLionel Sambucor newline character may be used to delimit the regular expression.
257*0a6a1f1dSLionel SambucThe opening delimiter needs to be preceded by a backslash
258*0a6a1f1dSLionel Sambucunless it is a slash.
259*0a6a1f1dSLionel SambucFor example, the context address
260*0a6a1f1dSLionel Sambuc.Li \exabcx
261*0a6a1f1dSLionel Sambucis equivalent to
262*0a6a1f1dSLionel Sambuc.Li /abc/ .
263f789fee2SBen GrasAlso, putting a backslash character before the delimiting character
264*0a6a1f1dSLionel Sambucwithin the regular expression causes the character to be treated literally.
265*0a6a1f1dSLionel SambucFor example, in the context address
266*0a6a1f1dSLionel Sambuc.Li \exabc\exdefx ,
267*0a6a1f1dSLionel Sambucthe RE delimiter is an
268f789fee2SBen Gras.Dq x
269f789fee2SBen Grasand the second
270f789fee2SBen Gras.Dq x
271f789fee2SBen Grasstands for itself, so that the regular expression is
272f789fee2SBen Gras.Dq abcxdef .
273*0a6a1f1dSLionel Sambuc.Pp
274f789fee2SBen Gras.It
275f789fee2SBen GrasThe escape sequence \en matches a newline character embedded in the
276f789fee2SBen Graspattern space.
277*0a6a1f1dSLionel SambucYou cannot, however, use a literal newline character in an address or
278f789fee2SBen Grasin the substitute command.
279f789fee2SBen Gras.El
280f789fee2SBen Gras.Pp
281f789fee2SBen GrasOne special feature of
282f789fee2SBen Gras.Nm
283f789fee2SBen Grasregular expressions is that they can default to the last regular
284f789fee2SBen Grasexpression used.
285*0a6a1f1dSLionel SambucIf a regular expression is empty, i.e., just the delimiter characters
286*0a6a1f1dSLionel Sambucare specified, the last regular expression encountered is used instead.
287f789fee2SBen GrasThe last regular expression is defined as the last regular expression
288f789fee2SBen Grasused as part of an address or substitute command, and at run-time, not
289f789fee2SBen Grascompile-time.
290f789fee2SBen GrasFor example, the command
291f789fee2SBen Gras.Dq /abc/s//XXX/
292f789fee2SBen Graswill substitute
293f789fee2SBen Gras.Dq XXX
294f789fee2SBen Grasfor the pattern
295f789fee2SBen Gras.Dq abc .
296*0a6a1f1dSLionel Sambuc.Ss "Sed Functions"
297f789fee2SBen GrasIn the following list of commands, the maximum number of permissible
298f789fee2SBen Grasaddresses for each command is indicated by [0addr], [1addr], or [2addr],
299f789fee2SBen Grasrepresenting zero, one, or two addresses.
300f789fee2SBen Gras.Pp
301f789fee2SBen GrasThe argument
302f789fee2SBen Gras.Em text
303f789fee2SBen Grasconsists of one or more lines.
304f789fee2SBen GrasTo embed a newline in the text, precede it with a backslash.
305f789fee2SBen GrasOther backslashes in text are deleted and the following character
306f789fee2SBen Grastaken literally.
307f789fee2SBen Gras.Pp
308f789fee2SBen GrasThe
309f789fee2SBen Gras.Dq r
310f789fee2SBen Grasand
311f789fee2SBen Gras.Dq w
312f789fee2SBen Grasfunctions take an optional file parameter, which should be separated
313f789fee2SBen Grasfrom the function letter by white space.
314f789fee2SBen GrasEach file given as an argument to
315f789fee2SBen Gras.Nm
316f789fee2SBen Grasis created (or its contents truncated) before any input processing begins.
317f789fee2SBen Gras.Pp
318f789fee2SBen GrasThe
319f789fee2SBen Gras.Dq b ,
320f789fee2SBen Gras.Dq r ,
321f789fee2SBen Gras.Dq s ,
322f789fee2SBen Gras.Dq t ,
323f789fee2SBen Gras.Dq w ,
324f789fee2SBen Gras.Dq y ,
325f789fee2SBen Gras.Dq \&! ,
326f789fee2SBen Grasand
327f789fee2SBen Gras.Dq \&:
328f789fee2SBen Grasfunctions all accept additional arguments.
329f789fee2SBen GrasThe following synopses indicate which arguments have to be separated from
330f789fee2SBen Grasthe function letters by white space characters.
331f789fee2SBen Gras.Pp
332f789fee2SBen GrasTwo of the functions take a function-list.
333f789fee2SBen GrasThis is a list of
334f789fee2SBen Gras.Nm
335f789fee2SBen Grasfunctions separated by newlines, as follows:
336f789fee2SBen Gras.Bd -literal -offset indent
337f789fee2SBen Gras{ function
338f789fee2SBen Gras  function
339f789fee2SBen Gras  ...
340f789fee2SBen Gras  function
341f789fee2SBen Gras}
342f789fee2SBen Gras.Ed
343f789fee2SBen Gras.Pp
344f789fee2SBen GrasThe
345f789fee2SBen Gras.Dq {
346f789fee2SBen Grascan be preceded by white space and can be followed by white space.
347f789fee2SBen GrasThe function can be preceded by white space.
348f789fee2SBen GrasThe terminating
349f789fee2SBen Gras.Dq }
350*0a6a1f1dSLionel Sambucmust be preceded by a newline, and may also be preceded by white space.
351*0a6a1f1dSLionel Sambuc.Pp
352f789fee2SBen Gras.Bl -tag -width "XXXXXX" -compact
353f789fee2SBen Gras.It [2addr] function-list
354f789fee2SBen GrasExecute function-list only when the pattern space is selected.
355*0a6a1f1dSLionel Sambuc.Pp
356f789fee2SBen Gras.It [1addr]a\e
357f789fee2SBen Gras.It text
358f789fee2SBen GrasWrite
359f789fee2SBen Gras.Em text
360f789fee2SBen Grasto standard output immediately before each attempt to read a line of input,
361f789fee2SBen Graswhether by executing the
362f789fee2SBen Gras.Dq N
363f789fee2SBen Grasfunction or by beginning a new cycle.
364*0a6a1f1dSLionel Sambuc.Pp
365f789fee2SBen Gras.It [2addr]b[label]
366f789fee2SBen GrasBranch to the
367f789fee2SBen Gras.Dq \&:
368f789fee2SBen Grasfunction with the specified label.
369f789fee2SBen GrasIf the label is not specified, branch to the end of the script.
370*0a6a1f1dSLionel Sambuc.Pp
371f789fee2SBen Gras.It [2addr]c\e
372f789fee2SBen Gras.It text
373f789fee2SBen GrasDelete the pattern space.
374f789fee2SBen GrasWith 0 or 1 address or at the end of a 2-address range,
375f789fee2SBen Gras.Em text
376f789fee2SBen Grasis written to the standard output.
377*0a6a1f1dSLionel Sambuc.Pp
378f789fee2SBen Gras.It [2addr]d
379f789fee2SBen GrasDelete the pattern space and start the next cycle.
380*0a6a1f1dSLionel Sambuc.Pp
381f789fee2SBen Gras.It [2addr]D
382f789fee2SBen GrasDelete the initial segment of the pattern space through the first
383f789fee2SBen Grasnewline character and start the next cycle.
384*0a6a1f1dSLionel Sambuc.Pp
385f789fee2SBen Gras.It [2addr]g
386f789fee2SBen GrasReplace the contents of the pattern space with the contents of the
387f789fee2SBen Grashold space.
388*0a6a1f1dSLionel Sambuc.Pp
389f789fee2SBen Gras.It [2addr]G
390f789fee2SBen GrasAppend a newline character followed by the contents of the hold space
391f789fee2SBen Grasto the pattern space.
392*0a6a1f1dSLionel Sambuc.Pp
393f789fee2SBen Gras.It [2addr]h
394f789fee2SBen GrasReplace the contents of the hold space with the contents of the
395f789fee2SBen Graspattern space.
396*0a6a1f1dSLionel Sambuc.Pp
397f789fee2SBen Gras.It [2addr]H
398f789fee2SBen GrasAppend a newline character followed by the contents of the pattern space
399f789fee2SBen Grasto the hold space.
400*0a6a1f1dSLionel Sambuc.Pp
401f789fee2SBen Gras.It [1addr]i\e
402f789fee2SBen Gras.It text
403f789fee2SBen GrasWrite
404f789fee2SBen Gras.Em text
405f789fee2SBen Grasto the standard output.
406*0a6a1f1dSLionel Sambuc.Pp
407f789fee2SBen Gras.It [2addr]l
408f789fee2SBen Gras(The letter ell.)
409f789fee2SBen GrasWrite the pattern space to the standard output in a visually unambiguous
410f789fee2SBen Grasform.
411f789fee2SBen GrasThis form is as follows:
412*0a6a1f1dSLionel Sambuc.Pp
413f789fee2SBen Gras.Bl -tag -width "carriage-returnXX" -offset indent -compact
414f789fee2SBen Gras.It backslash
415f789fee2SBen Gras\e\e
416f789fee2SBen Gras.It alert
417f789fee2SBen Gras\ea
418f789fee2SBen Gras.It form-feed
419f789fee2SBen Gras\ef
420f789fee2SBen Gras.It carriage-return
421f789fee2SBen Gras\er
422f789fee2SBen Gras.It tab
423f789fee2SBen Gras\et
424f789fee2SBen Gras.It vertical tab
425f789fee2SBen Gras\ev
426f789fee2SBen Gras.El
427f789fee2SBen Gras.Pp
428f789fee2SBen GrasNonprintable characters are written as three-digit octal numbers (with a
429f789fee2SBen Graspreceding backslash) for each byte in the character (most significant byte
430f789fee2SBen Grasfirst).
431f789fee2SBen GrasLong lines are folded, with the point of folding indicated by displaying
432f789fee2SBen Grasa backslash followed by a newline.
433f789fee2SBen GrasThe end of each line is marked with a
434f789fee2SBen Gras.Dq $ .
435*0a6a1f1dSLionel Sambuc.Pp
436f789fee2SBen Gras.It [2addr]n
437f789fee2SBen GrasWrite the pattern space to the standard output if the default output has
438f789fee2SBen Grasnot been suppressed, and replace the pattern space with the next line of
439*0a6a1f1dSLionel Sambucinput.
440*0a6a1f1dSLionel Sambuc.Pp
441f789fee2SBen Gras.It [2addr]N
442f789fee2SBen GrasAppend the next line of input to the pattern space, using an embedded
443f789fee2SBen Grasnewline character to separate the appended material from the original
444f789fee2SBen Grascontents.
445f789fee2SBen GrasNote that the current line number changes.
446*0a6a1f1dSLionel Sambuc.Pp
447f789fee2SBen Gras.It [2addr]p
448f789fee2SBen GrasWrite the pattern space to standard output.
449*0a6a1f1dSLionel Sambuc.Pp
450f789fee2SBen Gras.It [2addr]P
451f789fee2SBen GrasWrite the pattern space, up to the first newline character to the
452f789fee2SBen Grasstandard output.
453*0a6a1f1dSLionel Sambuc.Pp
454f789fee2SBen Gras.It [1addr]q
455f789fee2SBen GrasBranch to the end of the script and quit without starting a new cycle.
456*0a6a1f1dSLionel Sambuc.Pp
457f789fee2SBen Gras.It [1addr]r file
458f789fee2SBen GrasCopy the contents of
459f789fee2SBen Gras.Em file
460f789fee2SBen Grasto the standard output immediately before the next attempt to read a
461f789fee2SBen Grasline of input.
462f789fee2SBen GrasIf
463f789fee2SBen Gras.Em file
464f789fee2SBen Grascannot be read for any reason, it is silently ignored and no error
465f789fee2SBen Grascondition is set.
466*0a6a1f1dSLionel Sambuc.Pp
467f789fee2SBen Gras.It [2addr]s/regular expression/replacement/flags
468f789fee2SBen GrasSubstitute the replacement string for the first instance of the regular
469f789fee2SBen Grasexpression in the pattern space.
470f789fee2SBen GrasAny character other than backslash or newline can be used instead of
471f789fee2SBen Grasa slash to delimit the RE and the replacement.
472f789fee2SBen GrasWithin the RE and the replacement, the RE delimiter itself can be used as
473f789fee2SBen Grasa literal character if it is preceded by a backslash.
474f789fee2SBen Gras.Pp
475f789fee2SBen GrasAn ampersand
476*0a6a1f1dSLionel Sambuc.Pq Dq &
477f789fee2SBen Grasappearing in the replacement is replaced by the string matching the RE.
478f789fee2SBen GrasThe special meaning of
479*0a6a1f1dSLionel Sambuc.Dq &
480f789fee2SBen Grasin this context can be suppressed by preceding it by a backslash.
481f789fee2SBen GrasThe string
482f789fee2SBen Gras.Dq \e# ,
483f789fee2SBen Graswhere
484f789fee2SBen Gras.Dq #
485f789fee2SBen Grasis a digit, is replaced by the text matched
486f789fee2SBen Grasby the corresponding backreference expression (see
487f789fee2SBen Gras.Xr re_format 7 ) .
488f789fee2SBen Gras.Pp
489f789fee2SBen GrasA line can be split by substituting a newline character into it.
490f789fee2SBen GrasTo specify a newline character in the replacement string, precede it with
491f789fee2SBen Grasa backslash.
492f789fee2SBen Gras.Pp
493f789fee2SBen GrasThe value of
494f789fee2SBen Gras.Em flags
495f789fee2SBen Grasin the substitute function is zero or more of the following:
496f789fee2SBen Gras.Bl -tag -width "XXXXXX" -offset indent
497*0a6a1f1dSLionel Sambuc.It Ar N
498*0a6a1f1dSLionel SambucMake the substitution only for the
499*0a6a1f1dSLionel Sambuc.Ar N Ns 'th
500*0a6a1f1dSLionel Sambucoccurrence of the regular expression in the pattern space.
501f789fee2SBen Gras.It g
502f789fee2SBen GrasMake the substitution for all non-overlapping matches of the
503f789fee2SBen Grasregular expression, not just the first one.
504f789fee2SBen Gras.It p
505f789fee2SBen GrasWrite the pattern space to standard output if a replacement was made.
506f789fee2SBen GrasIf the replacement string is identical to that which it replaces, it
507f789fee2SBen Grasis still considered to have been a replacement.
508f789fee2SBen Gras.It w Em file
509f789fee2SBen GrasAppend the pattern space to
510f789fee2SBen Gras.Em file
511f789fee2SBen Grasif a replacement was made.
512f789fee2SBen GrasIf the replacement string is identical to that which it replaces, it
513f789fee2SBen Grasis still considered to have been a replacement.
514*0a6a1f1dSLionel Sambuc.It i or I
515*0a6a1f1dSLionel SambucMatch the regular expression in a case-insensitive way.
516f789fee2SBen Gras.El
517*0a6a1f1dSLionel Sambuc.Pp
518f789fee2SBen Gras.It [2addr]t [label]
519f789fee2SBen GrasBranch to the
520f789fee2SBen Gras.Dq \&:
521f789fee2SBen Grasfunction bearing the label if any substitutions have been made since the
522f789fee2SBen Grasmost recent reading of an input line or execution of a
523f789fee2SBen Gras.Dq t
524f789fee2SBen Grasfunction.
525f789fee2SBen GrasIf no label is specified, branch to the end of the script.
526*0a6a1f1dSLionel Sambuc.Pp
527f789fee2SBen Gras.It [2addr]w Em file
528f789fee2SBen GrasAppend the pattern space to the
529f789fee2SBen Gras.Em file .
530*0a6a1f1dSLionel Sambuc.Pp
531f789fee2SBen Gras.It [2addr]x
532f789fee2SBen GrasSwap the contents of the pattern and hold spaces.
533*0a6a1f1dSLionel Sambuc.Pp
534f789fee2SBen Gras.It [2addr]y/string1/string2/
535f789fee2SBen GrasReplace all occurrences of characters in
536f789fee2SBen Gras.Em string1
537f789fee2SBen Grasin the pattern space with the corresponding characters from
538f789fee2SBen Gras.Em string2 .
539f789fee2SBen GrasAny character other than a backslash or newline can be used instead of
540f789fee2SBen Grasa slash to delimit the strings.
541f789fee2SBen GrasWithin
542f789fee2SBen Gras.Em string1
543f789fee2SBen Grasand
544f789fee2SBen Gras.Em string2 ,
545f789fee2SBen Grasa backslash followed by any character other than a newline is that literal
546f789fee2SBen Grascharacter, and a backslash followed by an ``n'' is replaced by a newline
547f789fee2SBen Grascharacter.
548*0a6a1f1dSLionel Sambuc.Pp
549f789fee2SBen Gras.It [2addr]!function
550f789fee2SBen Gras.It [2addr]!function-list
551f789fee2SBen GrasApply the function or function-list only to the lines that are
552f789fee2SBen Gras.Em not
553f789fee2SBen Grasselected by the address(es).
554*0a6a1f1dSLionel Sambuc.Pp
555f789fee2SBen Gras.It [0addr]:label
556f789fee2SBen GrasThis function does nothing; it bears a label to which the
557f789fee2SBen Gras.Dq b
558f789fee2SBen Grasand
559f789fee2SBen Gras.Dq t
560f789fee2SBen Grascommands may branch.
561*0a6a1f1dSLionel Sambuc.Pp
562f789fee2SBen Gras.It [1addr]=
563f789fee2SBen GrasWrite the line number to the standard output followed by a newline
564f789fee2SBen Grascharacter.
565*0a6a1f1dSLionel Sambuc.Pp
566f789fee2SBen Gras.It [0addr]
567f789fee2SBen GrasEmpty lines are ignored.
568*0a6a1f1dSLionel Sambuc.Pp
569f789fee2SBen Gras.It [0addr]#
570f789fee2SBen GrasThe
571f789fee2SBen Gras.Dq #
572f789fee2SBen Grasand the remainder of the line are ignored (treated as a comment), with
573f789fee2SBen Grasthe single exception that if the first two characters in the file are
574f789fee2SBen Gras.Dq #n ,
575f789fee2SBen Grasthe default output is suppressed.
576f789fee2SBen GrasThis is the same as specifying the
577f789fee2SBen Gras.Fl n
578f789fee2SBen Grasoption on the command line.
579f789fee2SBen Gras.El
580*0a6a1f1dSLionel Sambuc.Sh ENVIRONMENT
581f789fee2SBen GrasThe
582*0a6a1f1dSLionel Sambuc.Ev COLUMNS , LANG , LC_ALL , LC_CTYPE
583*0a6a1f1dSLionel Sambucand
584*0a6a1f1dSLionel Sambuc.Ev LC_COLLATE
585*0a6a1f1dSLionel Sambucenvironment variables affect the execution of
586f789fee2SBen Gras.Nm
587*0a6a1f1dSLionel Sambucas described in
588*0a6a1f1dSLionel Sambuc.Xr environ 7 .
589*0a6a1f1dSLionel Sambuc.Sh EXIT STATUS
590*0a6a1f1dSLionel Sambuc.Ex -std
591f789fee2SBen Gras.Sh SEE ALSO
592f789fee2SBen Gras.Xr awk 1 ,
593f789fee2SBen Gras.Xr ed 1 ,
594f789fee2SBen Gras.Xr grep 1 ,
595f789fee2SBen Gras.Xr regex 3 ,
596f789fee2SBen Gras.Xr re_format 7
597f789fee2SBen Gras.Sh STANDARDS
598f789fee2SBen GrasThe
599f789fee2SBen Gras.Nm
600*0a6a1f1dSLionel Sambucutility is expected to be a superset of the
601f789fee2SBen Gras.St -p1003.2
602f789fee2SBen Grasspecification.
603*0a6a1f1dSLionel Sambuc.Pp
604*0a6a1f1dSLionel SambucThe
605*0a6a1f1dSLionel Sambuc.Fl a , E , I ,
606*0a6a1f1dSLionel Sambucand
607*0a6a1f1dSLionel Sambuc.Fl i
608*0a6a1f1dSLionel Sambucoptions, the prefixing
609*0a6a1f1dSLionel Sambuc.Dq \&+
610*0a6a1f1dSLionel Sambucin the second member of an address range,
611*0a6a1f1dSLionel Sambucas well as the
612*0a6a1f1dSLionel Sambuc.Dq I
613*0a6a1f1dSLionel Sambucflag to the address regular expression and substitution command are
614*0a6a1f1dSLionel Sambucnon-standard
615*0a6a1f1dSLionel Sambuc.Fx
616*0a6a1f1dSLionel Sambucextensions and may not be available on other operating systems.
617f789fee2SBen Gras.Sh HISTORY
618f789fee2SBen GrasA
619f789fee2SBen Gras.Nm
620*0a6a1f1dSLionel Sambuccommand, written by
621*0a6a1f1dSLionel Sambuc.An L. E. McMahon ,
622*0a6a1f1dSLionel Sambucappeared in
623f789fee2SBen Gras.At v7 .
624*0a6a1f1dSLionel Sambuc.Sh AUTHORS
625*0a6a1f1dSLionel Sambuc.An "Diomidis D. Spinellis" Aq dds@FreeBSD.org
626*0a6a1f1dSLionel Sambuc.Sh BUGS
627*0a6a1f1dSLionel SambucMultibyte characters containing a byte with value 0x5C
628*0a6a1f1dSLionel Sambuc.Tn ( ASCII
629*0a6a1f1dSLionel Sambuc.Ql \e )
630*0a6a1f1dSLionel Sambucmay be incorrectly treated as line continuation characters in arguments to the
631*0a6a1f1dSLionel Sambuc.Dq a ,
632*0a6a1f1dSLionel Sambuc.Dq c
633*0a6a1f1dSLionel Sambucand
634*0a6a1f1dSLionel Sambuc.Dq i
635*0a6a1f1dSLionel Sambuccommands.
636*0a6a1f1dSLionel SambucMultibyte characters cannot be used as delimiters with the
637*0a6a1f1dSLionel Sambuc.Dq s
638*0a6a1f1dSLionel Sambucand
639*0a6a1f1dSLionel Sambuc.Dq y
640*0a6a1f1dSLionel Sambuccommands.
641