xref: /freebsd/usr.bin/sed/sed.1 (revision 06e482e60a60643b7d60549870f45c6ba6c4c7a8)
19b50d902SRodney W. Grimes.\" Copyright (c) 1992, 1993
29b50d902SRodney W. Grimes.\"	The Regents of the University of California.  All rights reserved.
39b50d902SRodney W. Grimes.\"
49b50d902SRodney W. Grimes.\" This code is derived from software contributed to Berkeley by
59b50d902SRodney W. Grimes.\" the Institute of Electrical and Electronics Engineers, Inc.
69b50d902SRodney W. Grimes.\"
79b50d902SRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without
89b50d902SRodney W. Grimes.\" modification, are permitted provided that the following conditions
99b50d902SRodney W. Grimes.\" are met:
109b50d902SRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright
119b50d902SRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer.
129b50d902SRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright
139b50d902SRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer in the
149b50d902SRodney W. Grimes.\"    documentation and/or other materials provided with the distribution.
159b50d902SRodney W. Grimes.\" 3. All advertising materials mentioning features or use of this software
169b50d902SRodney W. Grimes.\"    must display the following acknowledgement:
179b50d902SRodney W. Grimes.\"	This product includes software developed by the University of
189b50d902SRodney W. Grimes.\"	California, Berkeley and its contributors.
199b50d902SRodney W. Grimes.\" 4. Neither the name of the University nor the names of its contributors
209b50d902SRodney W. Grimes.\"    may be used to endorse or promote products derived from this software
219b50d902SRodney W. Grimes.\"    without specific prior written permission.
229b50d902SRodney W. Grimes.\"
239b50d902SRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
249b50d902SRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
259b50d902SRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
269b50d902SRodney W. Grimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
279b50d902SRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
289b50d902SRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
299b50d902SRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
309b50d902SRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
319b50d902SRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
329b50d902SRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
339b50d902SRodney W. Grimes.\" SUCH DAMAGE.
349b50d902SRodney W. Grimes.\"
359b50d902SRodney W. Grimes.\"	@(#)sed.1	8.2 (Berkeley) 12/30/93
36c3aac50fSPeter Wemm.\" $FreeBSD$
379b50d902SRodney W. Grimes.\"
38cec2dd9fSRuslan Ermilov.Dd May 7, 2002
399b50d902SRodney W. Grimes.Dt SED 1
409b50d902SRodney W. Grimes.Os
419b50d902SRodney W. Grimes.Sh NAME
429b50d902SRodney W. Grimes.Nm sed
439b50d902SRodney W. Grimes.Nd stream editor
449b50d902SRodney W. Grimes.Sh SYNOPSIS
458fe908efSRuslan Ermilov.Nm
46175de1e6SBrian Feldman.Op Fl Ean
479b50d902SRodney W. Grimes.Ar command
4847dec781SRuslan Ermilov.Op Ar
498fe908efSRuslan Ermilov.Nm
50175de1e6SBrian Feldman.Op Fl Ean
519b50d902SRodney W. Grimes.Op Fl e Ar command
529b50d902SRodney W. Grimes.Op Fl f Ar command_file
53839af0c1SJuli Mallett.Op Fl i Ar extension
5447dec781SRuslan Ermilov.Op Ar
559b50d902SRodney W. Grimes.Sh DESCRIPTION
569b50d902SRodney W. GrimesThe
5773a08bb2SPhilippe Charnier.Nm
589b50d902SRodney W. Grimesutility reads the specified files, or the standard input if no files
599b50d902SRodney W. Grimesare specified, modifying the input as specified by a list of commands.
609b50d902SRodney W. GrimesThe input is then written to the standard output.
619b50d902SRodney W. Grimes.Pp
629b50d902SRodney W. GrimesA single command may be specified as the first argument to
638fe908efSRuslan Ermilov.Nm .
649b50d902SRodney W. GrimesMultiple commands may be specified by using the
659b50d902SRodney W. Grimes.Fl e
669b50d902SRodney W. Grimesor
679b50d902SRodney W. Grimes.Fl f
689b50d902SRodney W. Grimesoptions.
699b50d902SRodney W. GrimesAll commands are applied to the input in the order they are specified
709b50d902SRodney W. Grimesregardless of their origin.
719b50d902SRodney W. Grimes.Pp
729b50d902SRodney W. GrimesThe following options are available:
739b50d902SRodney W. Grimes.Bl -tag -width indent
74175de1e6SBrian Feldman.It Fl E
75175de1e6SBrian FeldmanInterpret regular expressions as extended (modern) regular expressions
760ef1d1f5SBrian Feldmanrather than basic regular expressions (BRE's).
770ef1d1f5SBrian FeldmanThe
78175de1e6SBrian Feldman.Xr re_format 7
79175de1e6SBrian Feldmanmanual page fully describes both formats.
809b50d902SRodney W. Grimes.It Fl a
819b50d902SRodney W. GrimesThe files listed as parameters for the
829b50d902SRodney W. Grimes.Dq w
839b50d902SRodney W. Grimesfunctions are created (or truncated) before any processing begins,
849b50d902SRodney W. Grimesby default.
859b50d902SRodney W. GrimesThe
869b50d902SRodney W. Grimes.Fl a
879b50d902SRodney W. Grimesoption causes
8873a08bb2SPhilippe Charnier.Nm
899b50d902SRodney W. Grimesto delay opening each file until a command containing the related
909b50d902SRodney W. Grimes.Dq w
919b50d902SRodney W. Grimesfunction is applied to a line of input.
929b50d902SRodney W. Grimes.It Fl e Ar command
939b50d902SRodney W. GrimesAppend the editing commands specified by the
949b50d902SRodney W. Grimes.Ar command
959b50d902SRodney W. Grimesargument
969b50d902SRodney W. Grimesto the list of commands.
979b50d902SRodney W. Grimes.It Fl f Ar command_file
989b50d902SRodney W. GrimesAppend the editing commands found in the file
999b50d902SRodney W. Grimes.Ar command_file
1009b50d902SRodney W. Grimesto the list of commands.
1019b50d902SRodney W. GrimesThe editing commands should each be listed on a separate line.
102839af0c1SJuli Mallett.It Fl i Ar extension
103839af0c1SJuli MallettEdit files in-place, saving backups with the specified
104839af0c1SJuli Mallett.Ar extension .
1055d16412dSJuli MallettIf a zero-length
1065d16412dSJuli Mallett.Ar extension
1075d16412dSJuli Mallettis given, no backup will be saved.
1085d16412dSJuli MallettIt is not recommended to give a zero-length
1095d16412dSJuli Mallett.Ar extension
1105d16412dSJuli Mallettwhen in-place editing files, as you risk corruption or partial content
1115d16412dSJuli Mallettin situations where disk space is exhausted, etc.
1129b50d902SRodney W. Grimes.It Fl n
1139b50d902SRodney W. GrimesBy default, each line of input is echoed to the standard output after
1149b50d902SRodney W. Grimesall of the commands have been applied to it.
1159b50d902SRodney W. GrimesThe
1169b50d902SRodney W. Grimes.Fl n
1179b50d902SRodney W. Grimesoption suppresses this behavior.
1189b50d902SRodney W. Grimes.El
1199b50d902SRodney W. Grimes.Pp
1209b50d902SRodney W. GrimesThe form of a
12173a08bb2SPhilippe Charnier.Nm
1229b50d902SRodney W. Grimescommand is as follows:
123726b61abSRuslan Ermilov.Pp
1249b50d902SRodney W. Grimes.Dl [address[,address]]function[arguments]
125726b61abSRuslan Ermilov.Pp
1269b50d902SRodney W. GrimesWhitespace may be inserted before the first address and the function
1279b50d902SRodney W. Grimesportions of the command.
1289b50d902SRodney W. Grimes.Pp
1299b50d902SRodney W. GrimesNormally,
13073a08bb2SPhilippe Charnier.Nm
1319b50d902SRodney W. Grimescyclically copies a line of input, not including its terminating newline
1329b50d902SRodney W. Grimescharacter, into a
1339b50d902SRodney W. Grimes.Em "pattern space" ,
1349b50d902SRodney W. Grimes(unless there is something left after a
1359b50d902SRodney W. Grimes.Dq D
1369b50d902SRodney W. Grimesfunction),
1379b50d902SRodney W. Grimesapplies all of the commands with addresses that select that pattern space,
1389b50d902SRodney W. Grimescopies the pattern space to the standard output, appending a newline, and
1399b50d902SRodney W. Grimesdeletes the pattern space.
1409b50d902SRodney W. Grimes.Pp
1419b50d902SRodney W. GrimesSome of the functions use a
1429b50d902SRodney W. Grimes.Em "hold space"
1439b50d902SRodney W. Grimesto save all or part of the pattern space for subsequent retrieval.
1449b50d902SRodney W. Grimes.Sh "Sed Addresses"
1459b50d902SRodney W. GrimesAn address is not required, but if specified must be a number (that counts
1469b50d902SRodney W. Grimesinput lines
1479b50d902SRodney W. Grimescumulatively across input files), a dollar
148c4d9468eSRuslan Ermilov.Pq Dq $
1499b50d902SRodney W. Grimescharacter that addresses the last line of input, or a context address
1509b50d902SRodney W. Grimes(which consists of a regular expression preceded and followed by a
1519b50d902SRodney W. Grimesdelimiter).
1529b50d902SRodney W. Grimes.Pp
1539b50d902SRodney W. GrimesA command line with no addresses selects every pattern space.
1549b50d902SRodney W. Grimes.Pp
1559b50d902SRodney W. GrimesA command line with one address selects all of the pattern spaces
1569b50d902SRodney W. Grimesthat match the address.
1579b50d902SRodney W. Grimes.Pp
1581d2ed2f7SBill SwingleA command line with two addresses selects an inclusive range.  This
1591d2ed2f7SBill Swinglerange starts with the first pattern space that matches the first
1601d2ed2f7SBill Swingleaddress.  The end of the range is the next following pattern space
1611d2ed2f7SBill Swinglethat matches the second address.  If the second address is a number
1621d2ed2f7SBill Swingleless than or equal to the line number first selected, only that
1631d2ed2f7SBill Swingleline is selected.  In the case when the second address is a context
1641d2ed2f7SBill Swingleaddress, sed does not re-match the second address against the
1651d2ed2f7SBill Swinglepattern space that matched the first address.  Starting at the
1662642bed2SGiorgos Keramidasfirst line following the selected range,
16773a08bb2SPhilippe Charnier.Nm
1689b50d902SRodney W. Grimesstarts looking again for the first address.
1699b50d902SRodney W. Grimes.Pp
1709b50d902SRodney W. GrimesEditing commands can be applied to non-selected pattern spaces by use
1719b50d902SRodney W. Grimesof the exclamation character
172c4d9468eSRuslan Ermilov.Pq Dq \&!
1739b50d902SRodney W. Grimesfunction.
1749b50d902SRodney W. Grimes.Sh "Sed Regular Expressions"
1750ef1d1f5SBrian FeldmanThe regular expressions used in
1768fe908efSRuslan Ermilov.Nm ,
1770ef1d1f5SBrian Feldmanby default, are basic regular expressions (BREs, see
1780ef1d1f5SBrian Feldman.Xr re_format 7
1790ef1d1f5SBrian Feldmanfor more information).
18073a08bb2SPhilippe Charnier.Nm
181175de1e6SBrian Feldmancan use extended (modern) regular expressions instead if the
182175de1e6SBrian Feldman.Fl E
1830ef1d1f5SBrian Feldmanflag is given.
1840ef1d1f5SBrian FeldmanIn addition,
185175de1e6SBrian Feldman.Nm
186175de1e6SBrian Feldmanhas the following two additions to regular expressions:
187726b61abSRuslan Ermilov.Pp
1889b50d902SRodney W. Grimes.Bl -enum -compact
1899b50d902SRodney W. Grimes.It
1909b50d902SRodney W. GrimesIn a context address, any character other than a backslash
191c4d9468eSRuslan Ermilov.Pq Dq \e
1929b50d902SRodney W. Grimesor newline character may be used to delimit the regular expression.
1939b50d902SRodney W. GrimesAlso, putting a backslash character before the delimiting character
1949b50d902SRodney W. Grimescauses the character to be treated literally.
1959b50d902SRodney W. GrimesFor example, in the context address \exabc\exdefx, the RE delimiter
1969b50d902SRodney W. Grimesis an
1979b50d902SRodney W. Grimes.Dq x
1989b50d902SRodney W. Grimesand the second
1999b50d902SRodney W. Grimes.Dq x
2009b50d902SRodney W. Grimesstands for itself, so that the regular expression is
2019b50d902SRodney W. Grimes.Dq abcxdef .
202726b61abSRuslan Ermilov.Pp
2039b50d902SRodney W. Grimes.It
2049b50d902SRodney W. GrimesThe escape sequence \en matches a newline character embedded in the
2059b50d902SRodney W. Grimespattern space.
2069b50d902SRodney W. GrimesYou can't, however, use a literal newline character in an address or
2079b50d902SRodney W. Grimesin the substitute command.
2089b50d902SRodney W. Grimes.El
2099b50d902SRodney W. Grimes.Pp
2109b50d902SRodney W. GrimesOne special feature of
21173a08bb2SPhilippe Charnier.Nm
2129b50d902SRodney W. Grimesregular expressions is that they can default to the last regular
2139b50d902SRodney W. Grimesexpression used.
2149b50d902SRodney W. GrimesIf a regular expression is empty, i.e. just the delimiter characters
2159b50d902SRodney W. Grimesare specified, the last regular expression encountered is used instead.
2169b50d902SRodney W. GrimesThe last regular expression is defined as the last regular expression
2179b50d902SRodney W. Grimesused as part of an address or substitute command, and at run-time, not
2189b50d902SRodney W. Grimescompile-time.
2199b50d902SRodney W. GrimesFor example, the command
2209b50d902SRodney W. Grimes.Dq /abc/s//XXX/
2219b50d902SRodney W. Grimeswill substitute
2229b50d902SRodney W. Grimes.Dq XXX
2239b50d902SRodney W. Grimesfor the pattern
2249b50d902SRodney W. Grimes.Dq abc .
2259b50d902SRodney W. Grimes.Sh "Sed Functions"
2269b50d902SRodney W. GrimesIn the following list of commands, the maximum number of permissible
2279b50d902SRodney W. Grimesaddresses for each command is indicated by [0addr], [1addr], or [2addr],
2289b50d902SRodney W. Grimesrepresenting zero, one, or two addresses.
2299b50d902SRodney W. Grimes.Pp
2309b50d902SRodney W. GrimesThe argument
2319b50d902SRodney W. Grimes.Em text
2329b50d902SRodney W. Grimesconsists of one or more lines.
2339b50d902SRodney W. GrimesTo embed a newline in the text, precede it with a backslash.
2349b50d902SRodney W. GrimesOther backslashes in text are deleted and the following character
2359b50d902SRodney W. Grimestaken literally.
2369b50d902SRodney W. Grimes.Pp
2379b50d902SRodney W. GrimesThe
2389b50d902SRodney W. Grimes.Dq r
2399b50d902SRodney W. Grimesand
2409b50d902SRodney W. Grimes.Dq w
2419b50d902SRodney W. Grimesfunctions take an optional file parameter, which should be separated
2429b50d902SRodney W. Grimesfrom the function letter by white space.
2439b50d902SRodney W. GrimesEach file given as an argument to
24473a08bb2SPhilippe Charnier.Nm
2459b50d902SRodney W. Grimesis created (or its contents truncated) before any input processing begins.
2469b50d902SRodney W. Grimes.Pp
2479b50d902SRodney W. GrimesThe
2489b50d902SRodney W. Grimes.Dq b ,
2499b50d902SRodney W. Grimes.Dq r ,
2509b50d902SRodney W. Grimes.Dq s ,
2519b50d902SRodney W. Grimes.Dq t ,
2529b50d902SRodney W. Grimes.Dq w ,
2539b50d902SRodney W. Grimes.Dq y ,
2549b88faecSRuslan Ermilov.Dq \&! ,
2559b50d902SRodney W. Grimesand
2569b50d902SRodney W. Grimes.Dq \&:
2579b50d902SRodney W. Grimesfunctions all accept additional arguments.
2589b50d902SRodney W. GrimesThe following synopses indicate which arguments have to be separated from
2599b50d902SRodney W. Grimesthe function letters by white space characters.
2609b50d902SRodney W. Grimes.Pp
2619b50d902SRodney W. GrimesTwo of the functions take a function-list.
2629b50d902SRodney W. GrimesThis is a list of
26373a08bb2SPhilippe Charnier.Nm
2649b50d902SRodney W. Grimesfunctions separated by newlines, as follows:
2659b50d902SRodney W. Grimes.Bd -literal -offset indent
2669b50d902SRodney W. Grimes{ function
2679b50d902SRodney W. Grimes  function
2689b50d902SRodney W. Grimes  ...
2699b50d902SRodney W. Grimes  function
2709b50d902SRodney W. Grimes}
2719b50d902SRodney W. Grimes.Ed
2729b50d902SRodney W. Grimes.Pp
2739b50d902SRodney W. GrimesThe
2749b50d902SRodney W. Grimes.Dq {
2759b50d902SRodney W. Grimescan be preceded by white space and can be followed by white space.
2769b50d902SRodney W. GrimesThe function can be preceded by white space.
2779b50d902SRodney W. GrimesThe terminating
2789b50d902SRodney W. Grimes.Dq }
2799b50d902SRodney W. Grimesmust be preceded by a newline or optional white space.
280726b61abSRuslan Ermilov.Pp
2819b50d902SRodney W. Grimes.Bl -tag -width "XXXXXX" -compact
2829b50d902SRodney W. Grimes.It [2addr] function-list
2839b50d902SRodney W. GrimesExecute function-list only when the pattern space is selected.
284726b61abSRuslan Ermilov.Pp
2859b50d902SRodney W. Grimes.It [1addr]a\e
2869b50d902SRodney W. Grimes.It text
2879b50d902SRodney W. GrimesWrite
2889b50d902SRodney W. Grimes.Em text
2899b50d902SRodney W. Grimesto standard output immediately before each attempt to read a line of input,
2909b50d902SRodney W. Grimeswhether by executing the
2919b50d902SRodney W. Grimes.Dq N
2929b50d902SRodney W. Grimesfunction or by beginning a new cycle.
293726b61abSRuslan Ermilov.Pp
29453daef24SAndreas Schulz.It [2addr]b[label]
2959b50d902SRodney W. GrimesBranch to the
2969b50d902SRodney W. Grimes.Dq \&:
2979b50d902SRodney W. Grimesfunction with the specified label.
2989b50d902SRodney W. GrimesIf the label is not specified, branch to the end of the script.
299726b61abSRuslan Ermilov.Pp
3009b50d902SRodney W. Grimes.It [2addr]c\e
3019b50d902SRodney W. Grimes.It text
3029b50d902SRodney W. GrimesDelete the pattern space.
3039b50d902SRodney W. GrimesWith 0 or 1 address or at the end of a 2-address range,
3049b50d902SRodney W. Grimes.Em text
3059b50d902SRodney W. Grimesis written to the standard output.
306726b61abSRuslan Ermilov.Pp
3079b50d902SRodney W. Grimes.It [2addr]d
3089b50d902SRodney W. GrimesDelete the pattern space and start the next cycle.
309726b61abSRuslan Ermilov.Pp
3109b50d902SRodney W. Grimes.It [2addr]D
3119b50d902SRodney W. GrimesDelete the initial segment of the pattern space through the first
3129b50d902SRodney W. Grimesnewline character and start the next cycle.
313726b61abSRuslan Ermilov.Pp
3149b50d902SRodney W. Grimes.It [2addr]g
3159b50d902SRodney W. GrimesReplace the contents of the pattern space with the contents of the
3169b50d902SRodney W. Grimeshold space.
317726b61abSRuslan Ermilov.Pp
3189b50d902SRodney W. Grimes.It [2addr]G
3199b50d902SRodney W. GrimesAppend a newline character followed by the contents of the hold space
3209b50d902SRodney W. Grimesto the pattern space.
321726b61abSRuslan Ermilov.Pp
3229b50d902SRodney W. Grimes.It [2addr]h
3239b50d902SRodney W. GrimesReplace the contents of the hold space with the contents of the
3249b50d902SRodney W. Grimespattern space.
325726b61abSRuslan Ermilov.Pp
3269b50d902SRodney W. Grimes.It [2addr]H
3279b50d902SRodney W. GrimesAppend a newline character followed by the contents of the pattern space
3289b50d902SRodney W. Grimesto the hold space.
329726b61abSRuslan Ermilov.Pp
3309b50d902SRodney W. Grimes.It [1addr]i\e
3319b50d902SRodney W. Grimes.It text
3329b50d902SRodney W. GrimesWrite
3339b50d902SRodney W. Grimes.Em text
3349b50d902SRodney W. Grimesto the standard output.
335726b61abSRuslan Ermilov.Pp
3369b50d902SRodney W. Grimes.It [2addr]l
3379b50d902SRodney W. Grimes(The letter ell.)
3389b50d902SRodney W. GrimesWrite the pattern space to the standard output in a visually unambiguous
3399b50d902SRodney W. Grimesform.
3409b50d902SRodney W. GrimesThis form is as follows:
341726b61abSRuslan Ermilov.Pp
3429b50d902SRodney W. Grimes.Bl -tag -width "carriage-returnXX" -offset indent -compact
3439b50d902SRodney W. Grimes.It backslash
34407847cc8SMike Pritchard\e\e
3459b50d902SRodney W. Grimes.It alert
3469b50d902SRodney W. Grimes\ea
3479b50d902SRodney W. Grimes.It form-feed
3489b50d902SRodney W. Grimes\ef
3499b50d902SRodney W. Grimes.It carriage-return
3509b50d902SRodney W. Grimes\er
3519b50d902SRodney W. Grimes.It tab
3529b50d902SRodney W. Grimes\et
3539b50d902SRodney W. Grimes.It vertical tab
3549b50d902SRodney W. Grimes\ev
3559b50d902SRodney W. Grimes.El
3569b50d902SRodney W. Grimes.Pp
3579b50d902SRodney W. GrimesNonprintable characters are written as three-digit octal numbers (with a
3589b50d902SRodney W. Grimespreceding backslash) for each byte in the character (most significant byte
3599b50d902SRodney W. Grimesfirst).
3609b50d902SRodney W. GrimesLong lines are folded, with the point of folding indicated by displaying
3619b50d902SRodney W. Grimesa backslash followed by a newline.
3629b50d902SRodney W. GrimesThe end of each line is marked with a
3639b50d902SRodney W. Grimes.Dq $ .
364726b61abSRuslan Ermilov.Pp
3659b50d902SRodney W. Grimes.It [2addr]n
3669b50d902SRodney W. GrimesWrite the pattern space to the standard output if the default output has
3679b50d902SRodney W. Grimesnot been suppressed, and replace the pattern space with the next line of
3689b50d902SRodney W. Grimesinput.
369726b61abSRuslan Ermilov.Pp
3709b50d902SRodney W. Grimes.It [2addr]N
3719b50d902SRodney W. GrimesAppend the next line of input to the pattern space, using an embedded
3729b50d902SRodney W. Grimesnewline character to separate the appended material from the original
3739b50d902SRodney W. Grimescontents.
3749b50d902SRodney W. GrimesNote that the current line number changes.
375726b61abSRuslan Ermilov.Pp
3769b50d902SRodney W. Grimes.It [2addr]p
3779b50d902SRodney W. GrimesWrite the pattern space to standard output.
378726b61abSRuslan Ermilov.Pp
3799b50d902SRodney W. Grimes.It [2addr]P
3809b50d902SRodney W. GrimesWrite the pattern space, up to the first newline character to the
3819b50d902SRodney W. Grimesstandard output.
382726b61abSRuslan Ermilov.Pp
3839b50d902SRodney W. Grimes.It [1addr]q
3849b50d902SRodney W. GrimesBranch to the end of the script and quit without starting a new cycle.
385726b61abSRuslan Ermilov.Pp
3869b50d902SRodney W. Grimes.It [1addr]r file
3879b50d902SRodney W. GrimesCopy the contents of
3889b50d902SRodney W. Grimes.Em file
3899b50d902SRodney W. Grimesto the standard output immediately before the next attempt to read a
3909b50d902SRodney W. Grimesline of input.
3919b50d902SRodney W. GrimesIf
3929b50d902SRodney W. Grimes.Em file
3939b50d902SRodney W. Grimescannot be read for any reason, it is silently ignored and no error
3949b50d902SRodney W. Grimescondition is set.
395726b61abSRuslan Ermilov.Pp
3969b50d902SRodney W. Grimes.It [2addr]s/regular expression/replacement/flags
3979b50d902SRodney W. GrimesSubstitute the replacement string for the first instance of the regular
3989b50d902SRodney W. Grimesexpression in the pattern space.
3999b50d902SRodney W. GrimesAny character other than backslash or newline can be used instead of
4009b50d902SRodney W. Grimesa slash to delimit the RE and the replacement.
4019b50d902SRodney W. GrimesWithin the RE and the replacement, the RE delimiter itself can be used as
4029b50d902SRodney W. Grimesa literal character if it is preceded by a backslash.
4039b50d902SRodney W. Grimes.Pp
4049b50d902SRodney W. GrimesAn ampersand
405c4d9468eSRuslan Ermilov.Pq Dq &
4069b50d902SRodney W. Grimesappearing in the replacement is replaced by the string matching the RE.
4079b50d902SRodney W. GrimesThe special meaning of
4089b50d902SRodney W. Grimes.Dq &
4099b50d902SRodney W. Grimesin this context can be suppressed by preceding it by a backslash.
4109b50d902SRodney W. GrimesThe string
4119b50d902SRodney W. Grimes.Dq \e# ,
4129b50d902SRodney W. Grimeswhere
4139b50d902SRodney W. Grimes.Dq #
4149b50d902SRodney W. Grimesis a digit, is replaced by the text matched
4159b50d902SRodney W. Grimesby the corresponding backreference expression (see
4169b50d902SRodney W. Grimes.Xr re_format 7 ) .
4179b50d902SRodney W. Grimes.Pp
4189b50d902SRodney W. GrimesA line can be split by substituting a newline character into it.
4199b50d902SRodney W. GrimesTo specify a newline character in the replacement string, precede it with
4209b50d902SRodney W. Grimesa backslash.
4219b50d902SRodney W. Grimes.Pp
4229b50d902SRodney W. GrimesThe value of
4239b50d902SRodney W. Grimes.Em flags
4249b50d902SRodney W. Grimesin the substitute function is zero or more of the following:
4259b50d902SRodney W. Grimes.Bl -tag -width "XXXXXX" -offset indent
42606e482e6SRuslan Ermilov.It Ar N
4271fa600e8STim J. RobbinsMake the substitution only for the
42806e482e6SRuslan Ermilov.Ar N Ns 'th
4291fa600e8STim J. Robbinsoccurrence of the regular expression in the pattern space.
4309b50d902SRodney W. Grimes.It g
4319b50d902SRodney W. GrimesMake the substitution for all non-overlapping matches of the
4329b50d902SRodney W. Grimesregular expression, not just the first one.
4339b50d902SRodney W. Grimes.It p
4349b50d902SRodney W. GrimesWrite the pattern space to standard output if a replacement was made.
4359b50d902SRodney W. GrimesIf the replacement string is identical to that which it replaces, it
4369b50d902SRodney W. Grimesis still considered to have been a replacement.
4379b50d902SRodney W. Grimes.It w Em file
4389b50d902SRodney W. GrimesAppend the pattern space to
4399b50d902SRodney W. Grimes.Em file
4409b50d902SRodney W. Grimesif a replacement was made.
4419b50d902SRodney W. GrimesIf the replacement string is identical to that which it replaces, it
4429b50d902SRodney W. Grimesis still considered to have been a replacement.
4439b50d902SRodney W. Grimes.El
444726b61abSRuslan Ermilov.Pp
4459b50d902SRodney W. Grimes.It [2addr]t [label]
4469b50d902SRodney W. GrimesBranch to the
4479edc38efSSteve Price.Dq \&:
4489b50d902SRodney W. Grimesfunction bearing the label if any substitutions have been made since the
4499b50d902SRodney W. Grimesmost recent reading of an input line or execution of a
4509b50d902SRodney W. Grimes.Dq t
4519b50d902SRodney W. Grimesfunction.
4529b50d902SRodney W. GrimesIf no label is specified, branch to the end of the script.
453726b61abSRuslan Ermilov.Pp
4549b50d902SRodney W. Grimes.It [2addr]w Em file
4559b50d902SRodney W. GrimesAppend the pattern space to the
4569b50d902SRodney W. Grimes.Em file .
457726b61abSRuslan Ermilov.Pp
4589b50d902SRodney W. Grimes.It [2addr]x
4599b50d902SRodney W. GrimesSwap the contents of the pattern and hold spaces.
460726b61abSRuslan Ermilov.Pp
4619b50d902SRodney W. Grimes.It [2addr]y/string1/string2/
4629b50d902SRodney W. GrimesReplace all occurrences of characters in
4639b50d902SRodney W. Grimes.Em string1
4649b50d902SRodney W. Grimesin the pattern space with the corresponding characters from
4659b50d902SRodney W. Grimes.Em string2 .
4669b50d902SRodney W. GrimesAny character other than a backslash or newline can be used instead of
4679b50d902SRodney W. Grimesa slash to delimit the strings.
4689b50d902SRodney W. GrimesWithin
4699b50d902SRodney W. Grimes.Em string1
4709b50d902SRodney W. Grimesand
4719b50d902SRodney W. Grimes.Em string2 ,
4729b50d902SRodney W. Grimesa backslash followed by any character other than a newline is that literal
4739b50d902SRodney W. Grimescharacter, and a backslash followed by an ``n'' is replaced by a newline
4749b50d902SRodney W. Grimescharacter.
475726b61abSRuslan Ermilov.Pp
4769b50d902SRodney W. Grimes.It [2addr]!function
4779b50d902SRodney W. Grimes.It [2addr]!function-list
4789b50d902SRodney W. GrimesApply the function or function-list only to the lines that are
4799b50d902SRodney W. Grimes.Em not
4809b50d902SRodney W. Grimesselected by the address(es).
481726b61abSRuslan Ermilov.Pp
4829b50d902SRodney W. Grimes.It [0addr]:label
4839b50d902SRodney W. GrimesThis function does nothing; it bears a label to which the
4849b50d902SRodney W. Grimes.Dq b
4859b50d902SRodney W. Grimesand
4869b50d902SRodney W. Grimes.Dq t
4879b50d902SRodney W. Grimescommands may branch.
488726b61abSRuslan Ermilov.Pp
4899b50d902SRodney W. Grimes.It [1addr]=
4909b50d902SRodney W. GrimesWrite the line number to the standard output followed by a newline
4919b50d902SRodney W. Grimescharacter.
492726b61abSRuslan Ermilov.Pp
4939b50d902SRodney W. Grimes.It [0addr]
4949b50d902SRodney W. GrimesEmpty lines are ignored.
495726b61abSRuslan Ermilov.Pp
4969b50d902SRodney W. Grimes.It [0addr]#
4979b50d902SRodney W. GrimesThe
4989b50d902SRodney W. Grimes.Dq #
4999b50d902SRodney W. Grimesand the remainder of the line are ignored (treated as a comment), with
5009b50d902SRodney W. Grimesthe single exception that if the first two characters in the file are
5019b50d902SRodney W. Grimes.Dq #n ,
5029b50d902SRodney W. Grimesthe default output is suppressed.
5039b50d902SRodney W. GrimesThis is the same as specifying the
5049b50d902SRodney W. Grimes.Fl n
5059b50d902SRodney W. Grimesoption on the command line.
5069b50d902SRodney W. Grimes.El
50730e9580eSTim J. Robbins.Sh ENVIRONMENT
50830e9580eSTim J. RobbinsThe
50906e482e6SRuslan Ermilov.Ev COLUMNS , LANG , LC_ALL , LC_CTYPE
510e7cc3a21STim J. Robbinsand
511e7cc3a21STim J. Robbins.Ev LC_COLLATE
512e7cc3a21STim J. Robbinsenvironment variables affect the execution of
51330e9580eSTim J. Robbins.Nm
514e7cc3a21STim J. Robbinsas described in
515e7cc3a21STim J. Robbins.Xr environ 7 .
516dbb9d8f8SPhilippe Charnier.Sh DIAGNOSTICS
517d628d776SRuslan Ermilov.Ex -std
5189b50d902SRodney W. Grimes.Sh SEE ALSO
5199b50d902SRodney W. Grimes.Xr awk 1 ,
5209b50d902SRodney W. Grimes.Xr ed 1 ,
5219b50d902SRodney W. Grimes.Xr grep 1 ,
5229b50d902SRodney W. Grimes.Xr regex 3 ,
5239b50d902SRodney W. Grimes.Xr re_format 7
5249b50d902SRodney W. Grimes.Sh STANDARDS
5259b50d902SRodney W. GrimesThe
52673a08bb2SPhilippe Charnier.Nm
52742676968STim J. Robbinsutility is expected to be a superset of the
5289b50d902SRodney W. Grimes.St -p1003.2
5299b50d902SRodney W. Grimesspecification.
530839af0c1SJuli Mallett.Pp
531839af0c1SJuli MallettThe
532839af0c1SJuli Mallett.Fl i
533839af0c1SJuli Mallettoption is a non-standard
534839af0c1SJuli Mallett.Fx
535839af0c1SJuli Mallettextension and may not be available on other operating systems.
53642676968STim J. Robbins.Sh HISTORY
53742676968STim J. RobbinsA
53842676968STim J. Robbins.Nm
53942676968STim J. Robbinscommand appeared in
54042676968STim J. Robbins.At v7 .
541