24 (standard input default) to the standard output,
25 edited according to a script of commands.
28 option causes the script to be taken from file
30 these options accumulate.
40 option suppresses the default output;
42 causes all substitutions to be global, as if suffixed
48 to flush its output buffer after every newline.
50 A script consists of editing commands, one per line,
51 of the following form:
53 [\fIaddress\fR [\fL,\fI address\fR] ] \fIfunction\fR [\fIargument\fR ...]
57 cyclically copies a line of input into a
59 (unless there is something left after
66 select that pattern space,
67 and at the end of the script copies the pattern space
68 to the standard output (except under
70 and deletes the pattern space.
74 is either a decimal number that counts
75 input lines cumulatively across files, a
78 addresses the last line of input, or a context address,
79 .BI / regular-expression / \f1,
82 with the added convention that
85 newline embedded in the pattern space.
87 A command line with no addresses selects every pattern space.
90 one address selects each pattern space that matches the address.
93 two addresses selects the inclusive range from the first
94 pattern space that matches the first address through
95 the next pattern space that matches
97 (If the second address is a number less than or equal
98 to the line number first selected, only one
100 Thereafter the process is repeated, looking again for the
103 Editing commands can be applied to non-selected pattern
104 spaces by use of the negation function
110 consists of one or more lines,
111 all but the last of which end with
115 Backslashes in text are treated like backslashes
116 in the replacement string of an
119 and may be used to protect initial blanks and tabs
120 against the stripping that is done on
127 must terminate the command
128 line and must be preceded by exactly one blank.
131 is created before processing begins.
132 There can be at most 120 distinct
135 .TP \w'\fL!\ \fIfunction\fLXXX'u
145 reading the next input line.
154 is empty, branch to the end of the script.
162 Delete the pattern space.
163 With 0 or 1 address or at the end of a 2-address range, place
166 Start the next cycle.
169 Delete the pattern space.
170 Start the next cycle.
173 Delete the initial segment of the
174 pattern space through the first newline.
175 Start the next cycle.
178 Replace the contents of the pattern space
179 by the contents of the hold space.
182 Append the contents of the hold space to the pattern space.
185 Replace the contents of the hold space by the contents of the pattern space.
188 Append the contents of the pattern space to the hold space.
199 on the standard output.
202 Copy the pattern space to the standard output.
203 Replace the pattern space with the next line of input.
206 Append the next line of input to the pattern space
207 with an embedded newline.
208 (The current line number changes.)
212 Copy the pattern space to the standard output.
215 Copy the initial segment of the pattern space through
216 the first newline to the standard output.
220 Branch to the end of the script.
221 Do not start a new cycle.
226 Place them on the output before reading
229 .B s/\fIregular-expression\fP/\fIreplacement\fP/\fIflags
232 string for instances of the
233 .I regular-expression
234 in the pattern space.
235 Any character may be used instead of
237 For a fuller description see
245 Substitute for all non-overlapping instances of the
246 .I regular expression
251 Print the pattern space if a replacement was made.
255 Append the pattern space to
268 substitutions have been made since the most recent
269 reading of an input line or execution of a
273 is empty, branch to the end of the script.
279 Append the pattern space to
283 Exchange the contents of the pattern and hold spaces.
285 .B y/\fIstring1\fP/\fIstring2\fP/
287 Replace all occurrences of characters in
289 with the corresponding character in
308 selected by the address(es).
311 This command does nothing; it bears a
317 commands to branch to.
320 Place the current line number on the standard output as a line.
323 Execute the following commands through a matching
325 only when the pattern space is selected.
328 An empty command is ignored.
333 Print the first 10 lines of the file.
336 Delete empty lines from standard input.
338 .B sed 's/UNIX/& system/g'
339 Replace every instance of
345 sed 's/ *$// \fRdrop trailing blanks\fP
346 /^$/d \fRdrop empty lines\fP
347 s/ */\e \fRreplace blanks by newlines\fP
356 etc. one word to a line.
359 nroff -ms manuscript | sed '
361 /^$/p \fRif last line of file is empty, print it\fP
363 //N \fRif current line is empty, append next line\fP
364 /^\en$/D' \fRif two lines are empty, delete the first\fP
368 Delete all but one of each group of empty lines from a
369 formatted manuscript.
381 `SED \(em A Non-interactive Text Editor',
382 Unix Research System Programmer's Manual, Volume 2.
384 If input is from a pipe, buffering may consume
385 characters beyond a line on which a