Penguin
Annotated edit history of sed(1) version 1, including all changes. View license author blame.
Rev Author # Line
1 perry 1 SED
2 !!!SED
3 NAME
4 SYNOPSIS
5 DESCRIPTION
6 OPTIONS
7 Command Synopsis
8 Addresses
9 Regular expressions
10 Miscellaneous notes
11 SEE ALSO
12 BUGS
13 ----
14 !!NAME
15
16
17 sed - a Stream EDitor
18 !!SYNOPSIS
19
20
21 sed [[-n] [[-V] [[--quiet] [[--silent] [[--version] [[--help]
22 [[-e script] [[--expression=script]
23 [[-f script-file] [[--file=script-file]
24 [[script-if-no-other-script]
25 [[file...]
26 !!DESCRIPTION
27
28
29 ''Sed'' is a stream editor. A stream editor is used to
30 perform basic text transformations on an input stream (a
31 file or input from a pipeline). While in some ways similar
32 to an editor which permits scripted edits (such as
33 ''ed''), ''sed'' works by making only one pass over
34 the input(s), and is consequently more efficient. But it is
35 ''sed'''s ability to filter text in a pipeline which
36 particularly distinguishes it from other types of
37 editors.
38 !!OPTIONS
39
40
41 ''Sed'' may be invoked with the following command-line
42 options:
43
44
45 __-V__
46
47
48 __--version__
49
50
51 Print out the version of sed that is being run and a
52 copyright notice, then exit.
53
54
55 __-h__
56
57
58 __--help__
59
60
61 Print a usage message briefly summarizing these command-line
62 options and the bug-reporting address, then
63 exit.
64
65
66 __-n__
67
68
69 __--quiet__
70
71
72 __--silent__
73
74
75 By default, ''sed'' will print out the pattern space at
76 the end of each cycle through the script. These options
77 disable this automatic printing, and ''sed'' will only
78 produce output when explicitly told to via the __p__
79 command.
80
81
82 __-e__ ''script''
83
84
85 __--expression=__''script''
86
87
88 Add the commands in ''script'' to the set of commands to
89 be run while processing the input.
90
91
92 __-f__ ''script-file''
93
94
95 __--file=__''script-file''
96
97
98 Add the commands contained in the file ''script-file'' to
99 the set of commands to be run while processing the
100 input.
101
102
103 If no __-e__,__-f__,__--expression__, or
104 __--file__ options are given on the command-line, then
105 the first non-option argument on the command line is taken
106 to be the ''script'' to be executed.
107
108
109 If any command-line parameters remain after processing the
110 above, these parameters are interpreted as the names of
111 input files to be processed. A file name of __-__ refers
112 to the standard input stream. The standard input will
113 processed if no file names are specified.
114 !!Command Synopsis
115
116
117 This is just a brief synopsis of ''sed'' commands to
118 serve as a reminder to those who already know sed; other
119 documentation (such as the texinfo document) must be
120 consulted for fuller descriptions.
121
122
123 __Zero-address ``commands''__
124
125
126 : ''label''
127
128
129 Label for __b__ and __t__ commands.
130
131
132 #''comment''
133
134
135 The comment extends until the next newline (or the end of a
136 __-e__ script fragment).
137
138
139 }
140
141
142 The closing bracket of a { } block.
143
144
145 __Zero- or One- address commands__
146
147
148 =
149
150
151 Print the current line number.
152
153
154 a \
155
156
157 ''text''
158
159
160 Append ''text'', which has each embedded newline
161 preceeded by a backslash.
162
163
164 i \
165
166
167 ''text''
168
169
170 Insert ''text'', which has each embedded newline
171 preceeded by a backslash.
172
173
174 q
175
176
177 Immediately quit the ''sed'' script without processing
178 any more input, except that if auto-print is not diabled the
179 current pattern space will be printed.
180
181
182 r ''filename''
183
184
185 Append text read from ''filename''.
186
187
188 __Commands which accept address ranges__
189
190
191 {
192
193
194 Begin a block of commands (end with a }).
195
196
197 b ''label''
198
199
200 Branch to ''label''; if ''label'' is omitted, branch
201 to end of script.
202
203
204 t ''label''
205
206
207 If a s/// has done a successful substitution since the last
208 input line was read and since the last t command, then
209 branch to ''label''; if ''label'' is omitted, branch
210 to end of script.
211
212
213 c \
214
215
216 ''text''
217
218
219 Replace the selected lines with ''text'', which has each
220 embedded newline preceeded by a backslash.
221
222
223 d
224
225
226 Delete pattern space. Start next cycle.
227
228
229 D
230
231
232 Delete up to the first embedded newline in the pattern
233 space. Start next cycle, but skip reading from the input if
234 there is still data in the pattern space.
235
236
237 h H
238
239
240 Copy/append pattern space to hold space.
241
242
243 g G
244
245
246 Copy/append hold space to pattern space.
247
248
249 x
250
251
252 Exchange the contents of the hold and pattern
253 spaces.
254
255
256 l
257
258
259 List out the current line in a ``visually unambiguous''
260 form.
261
262
263 n N
264
265
266 Read/append the next line of input into the pattern
267 space.
268
269
270 p
271
272
273 Print the current pattern space.
274
275
276 P
277
278
279 Print up to the first embedded newline of the current
280 pattern space.
281
282
283 s/''regexp''/''replacement''/
284
285
286 Attempt to match ''regexp'' against the pattern space. If
287 successful, replace that portion matched with
288 ''replacement''. The ''replacement'' may contain the
289 special character ____ to refer to that portion of
290 the pattern space which matched, and the special escapes 1
291 through 9 to refer to the corresponding matching
292 sub-expressions in the ''regexp''.
293
294
295 w
296
297
298 ''filename'' Write the current pattern space to
299 ''filename''.
300
301
302 y/''source''/''dest''/
303
304
305 Transliterate the characters in the pattern space which
306 appear in ''source'' to the corresponding character in
307 ''dest''.
308 !!Addresses
309
310
311 ''Sed'' commands can be given with no addresses, in which
312 case the command will be executed for all input lines; with
313 one address, in which case the command will only be executed
314 for input lines which match that address; or with two
315 addresses, in which case the command will be executed for
316 all input lines which match the inclusive range of lines
317 starting from the first address and continuing to the second
318 address. Three things to note about address ranges: the
319 syntax is ''addr1'',''addr2'' (i.e., the addresses are
320 separated by a comma); the line which ''addr1'' matched
321 will always be accepted, even if ''addr2'' selects an
322 earlier line; and if ''addr2'' is a ''regexp'', it
323 will not be tested against the line that ''addr1''
324 matched.
325
326
327 After the address (or address-range), and before the
328 command, a __!__ may be inserted, which specifies that
329 the command shall only be executed if the address (or
330 address-range) does __not__ match.
331
332
333 The following address types are supported:
334
335
336 ''number''
337
338
339 Match only the specified line ''number''.
340
341
342 ''first''~''step''
343
344
345 Match every ''step'''th line starting with line
346 ''first''. For example, ``sed -n 1~2p'' will print all
347 the odd-numbered lines in the input stream, and the address
348 2~5 will match every fifth line, starting with the second.
349 (This is a GNU extension.)
350
351
352 $
353
354
355 Match the last line.
356
357
358 /''regexp''/
359
360
361 Match lines matching the regular expression
362 ''regexp''.
363
364
365 \__c__''regexp''__c__
366
367
368 Match lines matching the regular expression ''regexp''.
369 The __c__ may be any character.
370 !!Regular expressions
371
372
373 POSIX.2 BREs ''should'' be supported, but they aren't
374 completely yet. The __n__ sequence in a regular
375 expression matches the newline character. There are also
376 some GNU extensions. [[XXX FIXME: more needs to be said. At
377 the very least, a reference to another document which
378 describes what is supported should be given.]
379 !!Miscellaneous notes
380
381
382 This version of sed supports a \____
383 sequence in all regular expressions, the ''replacement''
384 part of a substitute (s) command, and in the ''source''
385 and ''dest'' parts of a transliterate (y) command. The \
386 is stripped, and the newline is kept.
387 !!SEE ALSO
388
389
390 awk(1), ed(1), expr(1),
391 emacs(1), perl(1), tr(1), vi(1),
392 regex(7) [[well, one ''ought'' to be written...
393 XXX], sed.info, any of various books on ''sed'', the
394 ''sed'' FAQ (http://www.wollery.demon.co.uk/sedtut10.txt,
395 http://www.ptug.org/sed/sedfaq.htm).
396 !!BUGS
397
398
399 E-mail bug reports to __bug-gnu-utils@gnu.org__. Be sure
400 to include the word ``sed'' somewhere in the ``Subject:''
401 field.
402 ----
This page is a man page (or other imported legacy content). We are unable to automatically determine the license status of this page.