Print this page
11622 clean up rarer mandoc lint warnings
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/man/man1/sed.1
+++ new/usr/src/man/man1/sed.1
1 1 .\" Copyright (c) 1992, 1993
2 2 .\" The Regents of the University of California. All rights reserved.
3 3 .\"
4 4 .\" Copyright 2011 Nexenta Systems, Inc. All rights reserved.
5 5 .\"
6 6 .\" This code is derived from software contributed to Berkeley by
7 7 .\" the Institute of Electrical and Electronics Engineers, Inc.
8 8 .\"
9 9 .\" Redistribution and use in source and binary forms, with or without
10 10 .\" modification, are permitted provided that the following conditions
11 11 .\" are met:
12 12 .\" 1. Redistributions of source code must retain the above copyright
13 13 .\" notice, this list of conditions and the following disclaimer.
14 14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 15 .\" notice, this list of conditions and the following disclaimer in the
16 16 .\" documentation and/or other materials provided with the distribution.
17 17 .\" 4. Neither the name of the University nor the names of its contributors
18 18 .\" may be used to endorse or promote products derived from this software
19 19 .\" without specific prior written permission.
20 20 .\"
21 21 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 22 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 23 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 24 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 25 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 26 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 27 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 28 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 29 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 30 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 31 .\" SUCH DAMAGE.
32 32 .\"
33 33 .TH SED 1 "Feb 14, 2015"
34 34 .SH NAME
35 35 \fBsed\fP
36 36 \- stream editor
37 37 .SH SYNOPSIS
38 38 \fBsed\fP
39 39 [\fB\-Ealnr\fP]
40 40 \fIcommand\fP
41 41 [\fIfile ...\fP]
42 42 .br
43 43 \fBsed\fP
44 44 [\fB\-Ealnr\fP]
45 45 [\fB\-e\fP \fIcommand\fP]
46 46 [\fB\-f\fP \fIcommand_file\fP]
47 47 [\fB\-I\fP[\fIextension\fP] | \fB\-i\fP[\fIextension\fP]]
48 48 [\fIfile ...\fP]
49 49 .SH DESCRIPTION
50 50 The
51 51 \fBsed\fP
52 52 utility reads the specified files, or the standard input if no files
53 53 are specified, modifying the input as specified by a list of commands.
54 54 The input is then written to the standard output.
55 55
56 56 A single command may be specified as the first argument to
57 57 \fB.\fP
58 58 Multiple commands may be specified by using the
59 59 \fB\-e\fP
60 60 or
61 61 \fB\-f\fP
62 62 options.
63 63 All commands are applied to the input in the order they are specified
64 64 regardless of their origin.
65 65
66 66 The following options are available:
67 67 .TP
68 68 \fB\-E\fP
69 69 Interpret regular expressions as extended (modern) regular expressions
70 70 rather than basic regular expressions (BRE's).
71 71 The
72 72 \fBregex\fP(5)
73 73 manual page fully describes both formats.
74 74 .TP
75 75 \fB\-a\fP
76 76 The files listed as parameters for the
77 77 ``w''
78 78 functions are created (or truncated) before any processing begins,
79 79 by default.
80 80 The
81 81 \fB\-a\fP
82 82 option causes
83 83 \fBsed\fP
84 84 to delay opening each file until a command containing the related
85 85 ``w''
86 86 function is applied to a line of input.
87 87 .TP
88 88 \fB\-e\fP \fIcommand\fP
89 89 Append the editing commands specified by the
90 90 \fIcommand\fP
91 91 argument
92 92 to the list of commands.
93 93 .TP
94 94 \fB\-f\fP \fIcommand_file\fP
95 95 Append the editing commands found in the file
96 96 \fIcommand_file\fP
97 97 to the list of commands.
98 98 The editing commands should each be listed on a separate line.
99 99 .TP
100 100 \fB\-I\fP[\fIextension\fP]
101 101 Edit files in-place, saving backups if \fIextension\fP was specified.
102 102 It is not recommended to omit saving backups when in-place editing files,
103 103 as you risk corruption or partial content in situations where disk
104 104 space is exhausted, etc.
105 105
106 106 Note that in-place editing with
107 107 \fB\-I\fP
108 108 still takes place in a single continuous line address space covering
109 109 all files, although each file preserves its individuality instead of
110 110 forming one output stream.
111 111 The line counter is never reset between files, address ranges can span
112 112 file boundaries, and the
113 113 ``$''
114 114 address matches only the last line of the last file.
115 115 (See
116 116 .B "Sed Addresses" . )
117 117 That can lead to unexpected results in many cases of in-place editing,
118 118 where using
119 119 \fB\-i\fP
120 120 is desired.
121 121 .TP
122 122 \fB\-i\fP[\fIextension\fP]
123 123 Edit files in-place similarly to
124 124 \fB\-I\fP,
125 125 but treat each file independently from other files.
126 126 In particular, line numbers in each file start at 1,
127 127 the
128 128 ``$''
129 129 address matches the last line of the current file,
130 130 and address ranges are limited to the current file.
131 131 (See
132 132 .B "Sed Addresses" . )
133 133 The net result is as though each file were edited by a separate
134 134 \fBsed\fP
135 135 instance.
136 136 .TP
137 137 \fB\-l\fP
138 138 Make output line buffered.
139 139 .TP
140 140 \fB\-n\fP
141 141 By default, each line of input is echoed to the standard output after
142 142 all of the commands have been applied to it.
143 143 The
144 144 \fB\-n\fP
145 145 option suppresses this behavior.
146 146 .TP
147 147 \fB\-r\fP
148 148 Same as
149 149 \fB\-E\fP
150 150 for compatibility with GNU sed.
151 151
152 152 The form of a
153 153 \fBsed\fP
154 154 command is as follows:
155 155
156 156 [address[,address]]function[arguments]
157 157
158 158 Whitespace may be inserted before the first address and the function
159 159 portions of the command.
160 160
161 161 Normally,
162 162 \fBsed\fP
163 163 cyclically copies a line of input, not including its terminating newline
164 164 character, into a
165 165 .IR "pattern space" ,
166 166 (unless there is something left after a
167 167 ``D''
168 168 function),
169 169 applies all of the commands with addresses that select that pattern space,
170 170 copies the pattern space to the standard output, appending a newline, and
171 171 deletes the pattern space.
172 172
173 173 Some of the functions use a
174 174 .IR "hold space"
175 175 to save all or part of the pattern space for subsequent retrieval.
176 176 .SH "Sed Addresses"
177 177 An address is not required, but if specified must have one of the
178 178 following formats:
179 179 .IP \(bu
180 180 a number that counts
181 181 input lines
182 182 cumulatively across input files (or in each file independently
183 183 if a
184 184 \fB\-i\fP
185 185 option is in effect);
186 186 .IP \(bu
187 187 a dollar
188 188 (``$'')
189 189 character that addresses the last line of input (or the last line
190 190 of the current file if a
191 191 \fB\-i\fP
192 192 option was specified);
193 193 .IP \(bu
194 194 a context address
195 195 that consists of a regular expression preceded and followed by a
196 196 delimiter. The closing delimiter can also optionally be followed by the
197 197 ``I''
198 198 character, to indicate that the regular expression is to be matched
199 199 in a case-insensitive way.
200 200
201 201 A command line with no addresses selects every pattern space.
202 202
203 203 A command line with one address selects all of the pattern spaces
204 204 that match the address.
205 205
206 206 A command line with two addresses selects an inclusive range.
207 207 This
208 208 range starts with the first pattern space that matches the first
209 209 address.
210 210 The end of the range is the next following pattern space
211 211 that matches the second address.
212 212 If the second address is a number
213 213 less than or equal to the line number first selected, only that
214 214 line is selected.
215 215 The number in the second address may be prefixed with a
216 216 (``\&+'')
217 217 to specify the number of lines to match after the first pattern.
218 218 In the case when the second address is a context
219 219 address,
220 220 \fBsed\fP
221 221 does not re-match the second address against the
222 222 pattern space that matched the first address.
223 223 Starting at the
224 224 first line following the selected range,
225 225 \fBsed\fP
226 226 starts looking again for the first address.
227 227
228 228 Editing commands can be applied to non-selected pattern spaces by use
229 229 of the exclamation character
230 230 (``\&!'')
231 231 function.
232 232 .SH "Sed Regular Expressions"
233 233 The regular expressions used in
234 234 \fB,\fP
235 235 by default, are basic regular expressions (BREs, see
236 236 \fBregex\fP(5)
237 237 for more information), but extended (modern) regular expressions can be used
238 238 instead if the
239 239 \fB\-E\fP
240 240 flag is given.
241 241 In addition,
242 242 \fBsed\fP
243 243 has the following two additions to regular expressions:
244 244
245 245 .IP 1.
246 246 In a context address, any character other than a backslash
247 247 (``\e'')
248 248 or newline character may be used to delimit the regular expression.
249 249 The opening delimiter needs to be preceded by a backslash
250 250 unless it is a slash.
251 251 For example, the context address
252 252 \exabcx
253 253 is equivalent to
254 254 /abc/ .
255 255 Also, putting a backslash character before the delimiting character
256 256 within the regular expression causes the character to be treated literally.
257 257 For example, in the context address
258 258 \exabc\exdefx ,
259 259 the RE delimiter is an
260 260 ``x''
261 261 and the second
262 262 ``x''
263 263 stands for itself, so that the regular expression is
264 264 ``abcxdef''.
265 265
266 266 .IP 2.
267 267 The escape sequence \en matches a newline character embedded in the
268 268 pattern space.
269 269 You cannot, however, use a literal newline character in an address or
270 270 in the substitute command.
271 271
272 272 One special feature of
273 273 \fBsed\fP
274 274 regular expressions is that they can default to the last regular
275 275 expression used.
276 276 If a regular expression is empty, i.e., just the delimiter characters
277 277 are specified, the last regular expression encountered is used instead.
278 278 The last regular expression is defined as the last regular expression
279 279 used as part of an address or substitute command, and at run-time, not
280 280 compile-time.
281 281 For example, the command
282 282 ``/abc/s//XXX/''
283 283 will substitute
284 284 ``XXX''
285 285 for the pattern
286 286 ``abc''.
287 287 .SH "Sed Functions"
288 288 In the following list of commands, the maximum number of permissible
289 289 addresses for each command is indicated by [0addr], [1addr], or [2addr],
290 290 representing zero, one, or two addresses.
291 291
292 292 The argument
293 293 .IR text
294 294 consists of one or more lines.
295 295 To embed a newline in the text, precede it with a backslash.
296 296 Other backslashes in text are deleted and the following character
297 297 taken literally.
298 298
299 299 The
300 300 ``r''
301 301 and
302 302 ``w''
303 303 functions take an optional file parameter, which should be separated
304 304 from the function letter by white space.
305 305 Each file given as an argument to
306 306 \fBsed\fP
307 307 is created (or its contents truncated) before any input processing begins.
308 308
309 309 The
310 310 ``b'',
311 311 ``r'',
312 312 ``s'',
313 313 ``t'',
314 314 ``w'',
315 315 ``y'',
316 316 ``\&!'',
317 317 and
318 318 ``\&:''
↓ open down ↓ |
318 lines elided |
↑ open up ↑ |
319 319 functions all accept additional arguments.
320 320 The following synopses indicate which arguments have to be separated from
321 321 the function letters by white space characters.
322 322
323 323 Two of the functions take a function-list.
324 324 This is a list of
325 325 \fBsed\fP
326 326 functions separated by newlines, as follows:
327 327
328 328 { function
329 -.br
330 329 function
331 -.br
332 330 ...
333 -.br
334 331 function
335 332 .br
336 333 }
337 -.br
338 334
339 335 The
340 336 ``{''
341 337 can be preceded by white space and can be followed by white space.
342 338 The function can be preceded by white space.
343 339 The terminating
344 340 ``}''
345 341 must be preceded by a newline or optional white space.
346 342
347 343 .TP
348 344 [2addr] function-list
349 345 Execute function-list only when the pattern space is selected.
350 346
351 347 .TP
352 348 [1addr]a\e
353 349 .TP
354 350 text
355 351 Write
356 352 .IR text
357 353 to standard output immediately before each attempt to read a line of input,
358 354 whether by executing the
359 355 ``N''
360 356 function or by beginning a new cycle.
361 357
362 358 .TP
363 359 [2addr]b[label]
364 360 Branch to the
365 361 ``\&:''
366 362 function with the specified label.
367 363 If the label is not specified, branch to the end of the script.
368 364
369 365 .TP
370 366 [2addr]c\e
371 367 .TP
372 368 text
373 369 Delete the pattern space.
374 370 With 0 or 1 address or at the end of a 2-address range,
375 371 .IR text
376 372 is written to the standard output.
377 373
378 374 .TP
379 375 [2addr]d
380 376 Delete the pattern space and start the next cycle.
381 377
382 378 .TP
383 379 [2addr]D
384 380 Delete the initial segment of the pattern space through the first
385 381 newline character and start the next cycle.
386 382
387 383 .TP
388 384 [2addr]g
389 385 Replace the contents of the pattern space with the contents of the
390 386 hold space.
391 387
392 388 .TP
393 389 [2addr]G
394 390 Append a newline character followed by the contents of the hold space
395 391 to the pattern space.
396 392
397 393 .TP
398 394 [2addr]h
399 395 Replace the contents of the hold space with the contents of the
400 396 pattern space.
401 397
402 398 .TP
403 399 [2addr]H
404 400 Append a newline character followed by the contents of the pattern space
405 401 to the hold space.
406 402
407 403 .TP
408 404 [1addr]i\e
409 405 .TP
410 406 text
411 407 Write
412 408 .IR text
413 409 to the standard output.
414 410
415 411 .TP
416 412 [2addr]l
417 413 (The letter ell.)
418 414 Write the pattern space to the standard output in a visually unambiguous
419 415 form.
420 416 This form is as follows:
421 417
422 418 .TP
423 419 backslash
424 420 \e\e
425 421 .TP
426 422 alert
427 423 \ea
428 424 .TP
429 425 form-feed
430 426 \ef
431 427 .TP
432 428 carriage-return
433 429 \er
434 430 .TP
435 431 tab
436 432 \et
437 433 .TP
438 434 vertical tab
439 435 \ev
440 436
441 437 Nonprintable characters are written as three-digit octal numbers (with a
442 438 preceding backslash) for each byte in the character (most significant byte
443 439 first).
444 440 Long lines are folded, with the point of folding indicated by displaying
445 441 a backslash followed by a newline.
446 442 The end of each line is marked with a
447 443 ``$''.
448 444
449 445 .TP
450 446 [2addr]n
451 447 Write the pattern space to the standard output if the default output has
452 448 not been suppressed, and replace the pattern space with the next line of
453 449 input.
454 450
455 451 .TP
456 452 [2addr]N
457 453 Append the next line of input to the pattern space, using an embedded
458 454 newline character to separate the appended material from the original
459 455 contents.
460 456 Note that the current line number changes.
461 457
462 458 .TP
463 459 [2addr]p
464 460 Write the pattern space to standard output.
465 461
466 462 .TP
467 463 [2addr]P
468 464 Write the pattern space, up to the first newline character to the
469 465 standard output.
470 466
471 467 .TP
472 468 [1addr]q
473 469 Branch to the end of the script and quit without starting a new cycle.
474 470
475 471 .TP
476 472 [1addr]r file
477 473 Copy the contents of
478 474 .IR file
479 475 to the standard output immediately before the next attempt to read a
480 476 line of input.
481 477 If
482 478 .IR file
483 479 cannot be read for any reason, it is silently ignored and no error
484 480 condition is set.
485 481
486 482 .TP
487 483 [2addr]s/regular expression/replacement/flags
488 484 Substitute the replacement string for the first instance of the regular
489 485 expression in the pattern space.
490 486 Any character other than backslash or newline can be used instead of
491 487 a slash to delimit the RE and the replacement.
492 488 Within the RE and the replacement, the RE delimiter itself can be used as
493 489 a literal character if it is preceded by a backslash.
494 490
495 491 An ampersand
496 492 (``&'')
497 493 appearing in the replacement is replaced by the string matching the RE.
498 494 The special meaning of
499 495 ``&''
500 496 in this context can be suppressed by preceding it by a backslash.
501 497 The string
502 498 ``\e#'',
503 499 where
504 500 ``#''
505 501 is a digit, is replaced by the text matched
506 502 by the corresponding backreference expression (see
507 503 \fBregex\fP(5)) .
508 504
509 505 A line can be split by substituting a newline character into it.
510 506 To specify a newline character in the replacement string, precede it with
511 507 a backslash.
512 508
513 509 The value of
514 510 .IR flags
515 511 in the substitute function is zero or more of the following:
516 512 .TP
517 513 \fIN\fP
518 514 Make the substitution only for the
519 515 \fIN\fP'th
520 516 occurrence of the regular expression in the pattern space.
521 517 .TP
522 518 g
523 519 Make the substitution for all non-overlapping matches of the
524 520 regular expression, not just the first one.
525 521 .TP
526 522 p
527 523 Write the pattern space to standard output if a replacement was made.
528 524 If the replacement string is identical to that which it replaces, it
529 525 is still considered to have been a replacement.
530 526 .TP
531 527 w file
532 528 Append the pattern space to
533 529 .IR file
534 530 if a replacement was made.
535 531 If the replacement string is identical to that which it replaces, it
536 532 is still considered to have been a replacement.
537 533 .TP
538 534 I
539 535 Match the regular expression in a case-insensitive way.
540 536
541 537 .TP
542 538 [2addr]t [label]
543 539 Branch to the
544 540 ``\&:''
545 541 function bearing the label if any substitutions have been made since the
546 542 most recent reading of an input line or execution of a
547 543 ``t''
548 544 function.
549 545 If no label is specified, branch to the end of the script.
550 546
551 547 .TP
552 548 [2addr]w file
553 549 Append the pattern space to the
554 550 .IR file .
555 551
556 552 .TP
557 553 [2addr]x
558 554 Swap the contents of the pattern and hold spaces.
559 555
560 556 .TP
561 557 [2addr]y/string1/string2/
562 558 Replace all occurrences of characters in
563 559 .IR string1
564 560 in the pattern space with the corresponding characters from
565 561 .IR string2 .
566 562 Any character other than a backslash or newline can be used instead of
567 563 a slash to delimit the strings.
568 564 Within
569 565 .IR string1
570 566 and
571 567 .IR string2 ,
572 568 a backslash followed by any character other than a newline is that literal
573 569 character, and a backslash followed by an ``n'' is replaced by a newline
574 570 character.
575 571
576 572 .TP
577 573 [2addr]!function
578 574 .TP
579 575 [2addr]!function-list
580 576 Apply the function or function-list only to the lines that are
581 577 .IR not
582 578 selected by the address(es).
583 579
584 580 .TP
585 581 [0addr]:label
586 582 This function does nothing; it bears a label to which the
587 583 ``b''
588 584 and
589 585 ``t''
590 586 commands may branch.
591 587
592 588 .TP
593 589 [1addr]=
594 590 Write the line number to the standard output followed by a newline
595 591 character.
596 592
597 593 .TP
598 594 [0addr]
599 595 Empty lines are ignored.
600 596
601 597 .TP
602 598 [0addr]#
603 599 The
604 600 ``#''
605 601 and the remainder of the line are ignored (treated as a comment), with
606 602 the single exception that if the first two characters in the file are
607 603 ``#n'',
608 604 the default output is suppressed.
609 605 This is the same as specifying the
610 606 \fB\-n\fP
611 607 option on the command line.
612 608 .SH ENVIRONMENT
613 609 The
614 610 .IR COLUMNS , LANG , LC_ALL , LC_CTYPE
615 611 and
616 612 .IR LC_COLLATE
617 613 environment variables affect the execution of
618 614 \fBsed\fP
619 615 as described in
620 616 \fBenviron\fP(5).
621 617 .SH EXIT STATUS
622 618 The \fBsed\fP utility exits 0 on success, and >0 if an error occurs.
623 619 .SH SEE ALSO
624 620 \fBawk\fP(1),
625 621 \fBed\fP(1),
626 622 \fBgrep\fP(1),
627 623 \fBregex\fP(5)
628 624 .SH STANDARDS
629 625 The
630 626 \fBsed\fP
631 627 utility is expected to be a superset of the IEEE Std 1003.2 (``POSIX.2'')
632 628 specification.
633 629
634 630 The
635 631 \fB\-E\fP, I , a
636 632 and
637 633 \fB\-i\fP
638 634 options, the prefixing
639 635 ``\&+''
640 636 in the second member of an address range,
641 637 as well as the
642 638 ``I''
643 639 flag to the address regular expression and substitution command are
644 640 non-standard extensions and may not be available on other operating systems.
645 641 .SH HISTORY
646 642 A
647 643 \fBsed\fP
648 644 command, written by L. E. McMahon, appeared in Version 7 AT&T UNIX.
649 645 .SH AUTHORS
650 646
651 647 "Diomidis D. Spinellis" <dds@FreeBSD.org>
652 648 .SH BUGS
653 649 Multibyte characters containing a byte with value 0x5C (ASCII `\e')
654 650 may be incorrectly treated as line continuation characters in arguments to the
655 651 ``a'',
656 652 ``c''
657 653 and
658 654 ``i''
659 655 commands.
660 656 Multibyte characters cannot be used as delimiters with the
661 657 ``s''
662 658 and
663 659 ``y''
664 660 commands.
↓ open down ↓ |
317 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX