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 ...]
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
266 substitutions have been made since the most recent
267 reading of an input line or execution of a
271 is empty, branch to the end of the script.
277 Append the pattern space to
281 Exchange the contents of the pattern and hold spaces.
283 .B y/\fIstring1\fP/\fIstring2\fP/
285 Replace all occurrences of characters in
287 with the corresponding character in
306 selected by the address(es).
309 This command does nothing; it bears a
315 commands to branch to.
318 Place the current line number on the standard output as a line.
321 Execute the following commands through a matching
323 only when the pattern space is selected.
326 An empty command is ignored.
331 Print the first 10 lines of the file.
334 Delete empty lines from standard input.
336 .B sed 's/UNIX/& system/g'
337 Replace every instance of
343 sed 's/ *$// \fRdrop trailing blanks\fP
344 /^$/d \fRdrop empty lines\fP
345 s/ */\e \fRreplace blanks by newlines\fP
354 etc. one word to a line.
357 nroff -ms manuscript | sed '
359 /^$/p \fRif last line of file is empty, print it\fP
361 //N \fRif current line is empty, append next line\fP
362 /^\en$/D' \fRif two lines are empty, delete the first\fP
366 Delete all but one of each group of empty lines from a
367 formatted manuscript.
369 .B /usr/local/plan9/src/cmd/sed.c
379 `SED \(em A Non-interactive Text Editor',
380 Unix Research System Programmer's Manual, Volume 2.
382 If input is from a pipe, buffering may consume
383 characters beyond a line on which a