27 (standard input default) to the standard output,
28 edited according to a script of commands.
31 option causes the script to be taken from file
33 these options accumulate.
43 option suppresses the default output;
45 causes all substitutions to be global, as if suffixed
48 A script consists of editing commands, one per line,
49 of the following form:
51 [\fIaddress\fR [\fL,\fI address\fR] ] \fIfunction\fR [\fIargument\fR ...] [\fL;\fP]
55 cyclically copies a line of input into a
57 (unless there is something left after
64 select that pattern space,
65 and at the end of the script copies the pattern space
66 to the standard output (except under
68 and deletes the pattern space.
72 is either a decimal number that counts
73 input lines cumulatively across files, a
76 addresses the last line of input, or a context address,
77 .BI / regular-expression / \f1,
80 with the added convention that
83 newline embedded in the pattern space.
85 A command line with no addresses selects every pattern space.
88 one address selects each pattern space that matches the address.
91 two addresses selects the inclusive range from the first
92 pattern space that matches the first address through
93 the next pattern space that matches
95 (If the second address is a number less than or equal
96 to the line number first selected, only one
98 Thereafter the process is repeated, looking again for the
101 Editing commands can be applied to non-selected pattern
102 spaces by use of the negation function
108 consists of one or more lines,
109 all but the last of which end with
113 Backslashes in text are treated like backslashes
114 in the replacement string of an
117 and may be used to protect initial blanks and tabs
118 against the stripping that is done on
125 must terminate the command
126 line and must be preceded by exactly one blank.
129 is created before processing begins.
130 There can be at most 120 distinct
133 .TP \w'\fL!\ \fIfunction\fLXXX'u
143 reading the next input line.
152 is empty, branch to the end of the script.
160 Delete the pattern space.
161 With 0 or 1 address or at the end of a 2-address range, place
164 Start the next cycle.
167 Delete the pattern space.
168 Start the next cycle.
171 Delete the initial segment of the
172 pattern space through the first newline.
173 Start the next cycle.
176 Replace the contents of the pattern space
177 by the contents of the hold space.
180 Append the contents of the hold space to the pattern space.
183 Replace the contents of the hold space by the contents of the pattern space.
186 Append the contents of the pattern space to the hold space.
197 on the standard output.
200 Copy the pattern space to the standard output.
201 Replace the pattern space with the next line of input.
204 Append the next line of input to the pattern space
205 with an embedded newline.
206 (The current line number changes.)
210 Copy the pattern space to the standard output.
213 Copy the initial segment of the pattern space through
214 the first newline to the standard output.
218 Branch to the end of the script.
219 Do not start a new cycle.
224 Place them on the output before reading
227 .B s/\fIregular-expression\fP/\fIreplacement\fP/\fIflags
230 string for instances of the
231 .I regular-expression
232 in the pattern space.
233 Any character may be used instead of
235 For a fuller description see
243 Substitute for all non-overlapping instances of the
244 .I regular expression
249 Print the pattern space if a replacement was made.
253 Append the pattern space to
261 appearing in the replacement
262 is replaced by the string matching the regular expression.
268 are replaced by the text matched by the
270 regular subexpression
276 nested parenthesized subexpressions
279 is determined by counting occurrences of
281 starting from the left.
290 substitutions have been made since the most recent
291 reading of an input line or execution of a
295 is empty, branch to the end of the script.
301 Append the pattern space to
305 Exchange the contents of the pattern and hold spaces.
307 .B y/\fIstring1\fP/\fIstring2\fP/
309 Replace all occurrences of characters in
311 with the corresponding character in
330 selected by the address(es).
334 Ignore the rest of the line.
337 This command does nothing; it bears a
343 commands to branch to.
346 Place the current line number on the standard output as a line.
349 Execute the following commands through a matching
351 only when the pattern space is selected.
354 An empty command is ignored.
359 Print the first 10 lines of the file.
362 Delete empty lines from standard input.
364 .B sed 's/UNIX/& system/g'
365 Replace every instance of
371 sed 's/ *$// \fRdrop trailing blanks\fP
372 /^$/d \fRdrop empty lines\fP
373 s/ */\e \fRreplace blanks by newlines\fP
382 etc. one word to a line.
385 nroff -ms manuscript | sed '
387 /^$/p \fRif last line of file is empty, print it\fP
389 //N \fRif current line is empty, append next line\fP
390 /^\en$/D' \fRif two lines are empty, delete the first\fP
394 Delete all but one of each group of empty lines from a
395 formatted manuscript.
397 .B /sys/src/cmd/sed.c
407 `SED \(em A Non-interactive Text Editor',
408 Unix Research System Programmer's Manual, Volume 2.
410 If input is from a pipe, buffering may consume
411 characters beyond a line on which a