| sed '/ATT (NEW)/d'
[unix-history] / usr / src / old / sed / sed.1
CommitLineData
daacd5f0
CL
1.\" Copyright (c) 1990 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
2d33ba58 4.\"
daacd5f0
CL
5.\" @(#)sed.1 6.3 (Berkeley) %G%
6.\"
7.TH SED 1 "%Q"
2d33ba58
KM
8.AT 3
9.SH NAME
10sed \- stream editor
11.SH SYNOPSIS
12.B sed
13[
14.B \-n
15]
16[
17.B \-e
18script ] [
19.B \-f
20sfile ] [ file ] ...
21.SH DESCRIPTION
22.I Sed
23copies the named
24.I files
25(standard input default) to the standard output,
26edited according to a script of commands.
27The
28.B \-f
29option causes the script to be taken from file
30.IR sfile ;
31these options accumulate.
32If there is just one
33.B \-e
34option and no
35.BR \-f 's,
36the flag
37.B \-e
38may be omitted.
39The
40.B \-n
41option suppresses the default output.
42.PP
43A script consists of editing commands, one per line,
44of the following form:
45.IP
46[address [, address] ] function [arguments]
47.PP
48In normal operation
49.I sed
50cyclically copies a line of input into a
51.I pattern space
52(unless there is something left after
53a `D' command),
54applies in sequence
55all commands whose
56.I addresses
57select that pattern space,
58and at the end of the script copies the pattern space
59to the standard output (except under
60.BR \-n )
61and deletes the pattern space.
62.PP
63An
64.I address
65is either a decimal number that counts
66input lines cumulatively across files, a `$' that
67addresses the last line of input, or a context address,
68`/regular expression/', in the style of
69.IR ed (1)
70modified thus:
71.IP
72The escape sequence `\en' matches a
73newline embedded in the pattern space.
74.PP
75A command line with no addresses selects every pattern space.
76.PP
77A command line with
78one address selects each pattern space that matches the address.
79.PP
80A command line with
81two addresses selects the inclusive range from the first
82pattern space that matches the first address through
83the next pattern space that matches
84the second.
85(If the second address is a number less than or equal
86to the line number first selected, only one
87line is selected.)
88Thereafter the process is repeated, looking again for the
89first address.
90.PP
91Editing commands can be applied only to non-selected pattern
92spaces by use of the negation function `!' (below).
93.PP
94In the following list of functions the
95maximum number of permissible addresses
96for each function is indicated in parentheses.
97.PP
98An argument denoted
99.I text
100consists of one or more lines,
101all but the last of which end with `\e' to hide the
102newline.
103Backslashes in text are treated like backslashes
104in the replacement string of an `s' command,
105and may be used to protect initial blanks and tabs
106against the stripping that is done on
107every script line.
108.PP
109An argument denoted
110.I rfile
111or
112.I wfile
113must terminate the command
114line and must be preceded by exactly one blank.
115Each
116.I wfile
117is created before processing begins.
118There can be at most 10 distinct
119.I wfile
120arguments.
121.TP
122(1)\|a\e
123.br
124.ns
125.TP
126.I text
127.br
128Append.
129Place
130.I text
131on the output before
132reading the next input line.
133.TP
134.RI (2)\|b " label"
135Branch to the `:' command bearing the
136.IR label .
137If
138.I label
139is empty, branch to the end of the script.
140.TP
141(2)\|c\e
142.br
143.ns
144.TP
145.I text
146.br
147Change.
148Delete the pattern space.
149With 0 or 1 address or at the end of a 2-address range, place
150.I text
151on the output.
152Start the next cycle.
153.TP
154(2)\|d
155Delete the pattern space.
156Start the next cycle.
157.TP
158(2)\|D
159Delete the initial segment of the
160pattern space through the first newline.
161Start the next cycle.
162.TP
163(2)\|g
164Replace the contents of the pattern space
165by the contents of the hold space.
166.TP
167(2)\|G
168Append the contents of the hold space to the pattern space.
169.TP
170(2)\|h
171Replace the contents of the hold space by the contents of the pattern space.
172.TP
173(2)\|H
174Append the contents of the pattern space to the hold space.
175.TP
176(1)\|i\e
177.br
178.ns
179.TP
180.I text
181.br
182Insert.
183Place
184.I text
185on the standard output.
186.TP
187(2)\|n
188Copy the pattern space to the standard output.
189Replace the pattern space with the next line of input.
190.TP
191(2)\|N
192Append the next line of input to the pattern space
193with an embedded newline.
194(The current line number changes.)
195.TP
196(2)\|p
197Print.
198Copy the pattern space to the standard output.
199.TP
200(2)\|P
201Copy the initial segment of the pattern space through
202the first newline to the standard output.
203.TP
204(1)\|q
205Quit.
206Branch to the end of the script.
207Do not start a new cycle.
208.TP
209.RI (2)\|r " rfile"
210Read the contents of
211.IR rfile .
212Place them on the output before reading
213the next input line.
214.TP
215.RI (2)\|s /regular\ expression/replacement/flags
216Substitute the
217.I replacement
218string for instances of the
219.I regular expression
220in the pattern space.
221Any character may be used instead of `/'.
222For a fuller description see
223.IR ed (1).
224.I Flags
225is zero or more of
226.RS
227.TP
228g
229Global.
230Substitute for all nonoverlapping instances of the
231.I regular expression
232rather than just the
233first one.
234.TP
235p
236Print the pattern space if a replacement was made.
237.TP
238.RI w " wfile"
239Write.
240Append the pattern space to
241.I wfile
242if a replacement
243was made.
244.RE
245.TP
246.RI (2)\|t " label"
247Test.
248Branch to the `:' command bearing the
249.I label
250if any
251substitutions have been made since the most recent
252reading of an input line or execution of a `t'.
253If
254.I label
255is empty, branch to the end of the script.
256.TP
257.RI (2)\|w " wfile"
258Write.
259Append the pattern space to
260.IR wfile .
261.TP
262.RI (2)\|x
263Exchange the contents of the pattern and hold spaces.
264.TP
265.RI (2)\|y /string1/string2/
266Transform.
267Replace all occurrences of characters in
268.I string1
269with the corresponding character in
270.I string2.
271The lengths of
272.I
273string1
274and
275.I string2
276must be equal.
277.TP
278.RI (2)! " function"
279Don't.
280Apply the
281.I function
282(or group, if
283.I function
284is `{') only to lines
285.I not
286selected by the address(es).
287.TP
288.RI (0)\|: " label"
289This command does nothing; it bears a
290.I label
291for `b' and `t' commands to branch to.
292.TP
293(1)\|=
294Place the current line number on the standard output as a line.
295.TP
296(2)\|{
297Execute the following commands through a matching `}'
298only when the pattern space is selected.
299.TP
300(0)\|
301An empty command is ignored.
88fdc291
KB
302.TP
303(0)\|#
304If a \fI#\fP appears as the first character on a line of a script,
305then that entire line is treated as a comment, with one exception.
306If the first line of the script starts with the characters ``\fI#\fPn'',
307then the default output will be suppressed. The rest of the line after
308``\fI#\fPn'' will also be ignored. A script file must contain at least one
309non-comment line.
2d33ba58
KM
310.SH SEE ALSO
311ed(1), grep(1), awk(1), lex(1)