30 (standard input default) to the standard output,
31 edited according to a script of commands.
34 option causes the script to be taken from file
36 these options accumulate.
46 option suppresses the default output;
48 causes all substitutions to be global, as if suffixed
54 flushes its output buffers before reading in further input.
56 A script consists of editing commands, one per line,
57 of the following form:
59 [\fIaddress\fR [\fL,\fI address\fR] ] \fIfunction\fR [\fIargument\fR ...] [\fL;\fP]
63 cyclically copies a line of input into a
65 (unless there is something left after
72 select that pattern space,
73 and at the end of the script copies the pattern space
74 to the standard output (except under
76 and deletes the pattern space.
80 is either a decimal number that counts
81 input lines cumulatively across files, a
84 addresses the last line of input, or a context address,
85 .BI / regular-expression / \f1,
88 with the added convention that
91 newline embedded in the pattern space.
93 A command line with no addresses selects every pattern space.
96 one address selects each pattern space that matches the address.
99 two addresses selects the inclusive range from the first
100 pattern space that matches the first address through
101 the next pattern space that matches
103 (If the second address is a number less than or equal
104 to the line number first selected, only one
106 Thereafter the process is repeated, looking again for the
109 Editing commands can be applied to non-selected pattern
110 spaces by use of the negation function
116 consists of one or more lines,
117 all but the last of which end with
121 Backslashes in text are treated like backslashes
122 in the replacement string of an
125 and may be used to protect initial blanks and tabs
126 against the stripping that is done on
133 must terminate the command
134 line and must be preceded by exactly one blank.
137 is created before processing begins.
138 There can be at most 120 distinct
141 .TP \w'\fL!\ \fIfunction\fLXXX'u
151 reading the next input line.
160 is empty, branch to the end of the script.
168 Delete the pattern space.
169 With 0 or 1 address or at the end of a 2-address range, place
172 Start the next cycle.
175 Delete the pattern space.
176 Start the next cycle.
179 Delete the initial segment of the
180 pattern space through the first newline.
181 Start the next cycle.
184 Replace the contents of the pattern space
185 by the contents of the hold space.
188 Append the contents of the hold space to the pattern space.
191 Replace the contents of the hold space by the contents of the pattern space.
194 Append the contents of the pattern space to the hold space.
205 on the standard output.
208 Copy the pattern space to the standard output.
209 Replace the pattern space with the next line of input.
212 Append the next line of input to the pattern space
213 with an embedded newline.
214 (The current line number changes.)
218 Copy the pattern space to the standard output.
221 Copy the initial segment of the pattern space through
222 the first newline to the standard output.
226 Branch to the end of the script.
227 Do not start a new cycle.
232 Place them on the output before reading
235 .B s/\fIregular-expression\fP/\fIreplacement\fP/\fIflags
238 string for instances of the
239 .I regular-expression
240 in the pattern space.
241 Any character may be used instead of
243 For a fuller description see
251 Substitute for all non-overlapping instances of the
252 .I regular expression
257 Print the pattern space if a replacement was made.
261 Append the pattern space to
269 appearing in the replacement
270 is replaced by the string matching the regular expression.
276 are replaced by the text matched by the
278 regular subexpression
284 nested parenthesized subexpressions
287 is determined by counting occurrences of
289 starting from the left.
298 substitutions have been made since the most recent
299 reading of an input line or execution of a
303 is empty, branch to the end of the script.
309 Append the pattern space to
313 Exchange the contents of the pattern and hold spaces.
315 .B y/\fIstring1\fP/\fIstring2\fP/
317 Replace all occurrences of characters in
319 with the corresponding character in
338 selected by the address(es).
342 Ignore the rest of the line.
345 This command does nothing; it bears a
351 commands to branch to.
354 Place the current line number on the standard output as a line.
357 Execute the following commands through a matching
359 only when the pattern space is selected.
362 An empty command is ignored.
367 Print the first 10 lines of the file.
370 Delete empty lines from standard input.
372 .B sed 's/UNIX/& system/g'
373 Replace every instance of
379 sed 's/ *$// \fRdrop trailing blanks\fP
380 /^$/d \fRdrop empty lines\fP
381 s/ */\e \fRreplace blanks by newlines\fP
390 etc. one word to a line.
393 nroff -ms manuscript | sed '
395 /^$/p \fRif last line of file is empty, print it\fP
397 //N \fRif current line is empty, append next line\fP
398 /^\en$/D' \fRif two lines are empty, delete the first\fP
402 Delete all but one of each group of empty lines from a
403 formatted manuscript.
405 .B /sys/src/cmd/sed.c
415 `SED \(em A Non-interactive Text Editor',
416 Unix Research System Programmer's Manual, Volume 2.
418 If input is from a pipe, buffering may consume
419 characters beyond a line on which a
424 does not work as expected if