1 .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.28.
2 .TH SED "1" "December 2012" "sed 4.2.2" "User Commands"
4 sed \- stream editor for filtering and transforming text
7 [\fIOPTION\fR]... \fI{script-only-if-no-other-script} \fR[\fIinput-file\fR]...
11 \*(Sd is a stream editor.
12 A stream editor is used to perform basic text
13 transformations on an input stream
14 (a file or input from a pipeline).
15 While in some ways similar to an editor which
16 permits scripted edits (such as \fIed\fP),
17 \*(sd works by making only one pass over the
18 input(s), and is consequently more efficient.
19 But it is \*(sd's ability to filter text in a pipeline
20 which particularly distinguishes it from other types of
23 \fB\-n\fR, \fB\-\-quiet\fR, \fB\-\-silent\fR
25 suppress automatic printing of pattern space
27 \fB\-e\fR script, \fB\-\-expression\fR=\fIscript\fR
29 add the script to the commands to be executed
31 \fB\-f\fR script-file, \fB\-\-file\fR=\fIscript\-file\fR
33 add the contents of script-file to the commands to be executed
35 \fB\-\-follow\-symlinks\fR
37 follow symlinks when processing in place
39 \fB\-i[SUFFIX]\fR, \fB\-\-in\-place\fR[=\fISUFFIX\fR]
41 edit files in place (makes backup if SUFFIX supplied)
43 \fB\-l\fR N, \fB\-\-line\-length\fR=\fIN\fR
45 specify the desired line-wrap length for the `l' command
49 disable all GNU extensions.
51 \fB\-r\fR, \fB\-\-regexp\-extended\fR
53 use extended regular expressions in the script.
55 \fB\-s\fR, \fB\-\-separate\fR
57 consider files as separate rather than as a single continuous
60 \fB\-u\fR, \fB\-\-unbuffered\fR
62 load minimal amounts of data from the input files and flush
63 the output buffers more often
65 \fB\-z\fR, \fB\-\-null\-data\fR
67 separate lines by NUL characters
70 display this help and exit
73 output version information and exit
75 If no \fB\-e\fR, \fB\-\-expression\fR, \fB\-f\fR, or \fB\-\-file\fR option is given, then the first
76 non-option argument is taken as the sed script to interpret. All
77 remaining arguments are names of input files; if no input files are
78 specified, then the standard input is read.
80 GNU sed home page: <http://www.gnu.org/software/sed/>.
81 General help using GNU software: <http://www.gnu.org/gethelp/>.
82 E-mail bug reports to: <bug-sed@gnu.org>.
83 Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.
84 .SH "COMMAND SYNOPSIS"
85 This is just a brief synopsis of \*(sd commands to serve as
86 a reminder to those who already know \*(sd;
87 other documentation (such as the texinfo document)
88 must be consulted for fuller descriptions.
90 Zero-address ``commands''
100 The comment extends until the next newline (or the end of a
105 The closing bracket of a { } block.
107 Zero- or One- address commands
110 Print the current line number.
117 which has each embedded newline preceded by a backslash.
124 which has each embedded newline preceded by a backslash.
127 Immediately quit the \*(sd script without processing
128 any more input, except that if auto-print is not disabled
129 the current pattern space will be printed. The exit code
130 argument is a GNU extension.
133 Immediately quit the \*(sd script without processing
134 any more input. This is a GNU extension.
137 Append text read from
141 Append a line read from
143 Each invocation of the command reads a line from the file.
144 This is a GNU extension.
146 Commands which accept address ranges
149 Begin a block of commands (end with a }).
156 is omitted, branch to end of script.
161 Replace the selected lines with
163 which has each embedded newline preceded by a backslash.
166 Delete pattern space.
170 If pattern space contains no newline, start a normal new cycle as if
171 the d command was issued. Otherwise, delete text in the pattern
172 space up to the first newline, and restart cycle with the resultant
173 pattern space, without reading a new line of input.
176 Copy/append pattern space to hold space.
179 Copy/append hold space to pattern space.
182 List out the current line in a ``visually unambiguous'' form.
185 List out the current line in a ``visually unambiguous'' form,
188 characters. This is a GNU extension.
191 Read/append the next line of input into the pattern space.
194 Print the current pattern space.
197 Print up to the first embedded newline of the current pattern space.
199 .RI s/ regexp / replacement /
202 against the pattern space.
203 If successful, replace that portion matched
208 may contain the special character
210 to refer to that portion of the pattern space which matched,
211 and the special escapes \e1 through \e9 to refer to the
212 corresponding matching sub-expressions in the
216 If a s/// has done a successful substitution since the
217 last input line was read and since the last t or T
218 command, then branch to
222 is omitted, branch to end of script.
225 If no s/// has done a successful substitution since the
226 last input line was read and since the last t or T
227 command, then branch to
231 is omitted, branch to end of script. This is a GNU
235 Write the current pattern space to
239 Write the first line of the current pattern space to
241 This is a GNU extension.
244 Exchange the contents of the hold and pattern spaces.
246 .RI y/ source / dest /
247 Transliterate the characters in the pattern space which appear in
249 to the corresponding character in
253 \*(Sd commands can be given with no addresses, in which
254 case the command will be executed for all input lines;
255 with one address, in which case the command will only be executed
256 for input lines which match that address; or with two
257 addresses, in which case the command will be executed
258 for all input lines which match the inclusive range of
259 lines starting from the first address and continuing to
261 Three things to note about address ranges:
264 (i.e., the addresses are separated by a comma);
267 matched will always be accepted,
270 selects an earlier line;
275 it will not be tested against the line that
279 After the address (or address-range),
280 and before the command, a
283 which specifies that the command shall only be
284 executed if the address (or address-range) does
288 The following address types are supported:
291 Match only the specified line
293 (which increments cumulatively across files, unless the
295 option is specified on the command line).
300 line starting with line
302 For example, ``sed -n 1~2p'' will print all the odd-numbered lines in
303 the input stream, and the address 2~5 will match every fifth line,
304 starting with the second.
306 can be zero; in this case, \*(sd operates as if it were equal to
308 (This is an extension.)
314 Match lines matching the regular expression
317 .BI \fR\e\fPc regexp c
318 Match lines matching the regular expression
322 may be any character.
324 GNU \*(sd also supports some special 2-address forms:
327 Start out in "matched first address" state, until
334 matches the very first line of input the
336 form will be at the end of its range, whereas the
338 form will still be at the beginning of its range.
341 is a regular expression.
354 and the lines following
356 until the next line whose input line number is a multiple of
358 .SH "REGULAR EXPRESSIONS"
361 be supported, but they aren't completely because of performance
365 sequence in a regular expression matches the newline character,
372 E-mail bug reports to
373 .BR bug-sed@gnu.org .
374 Also, please include the output of ``sed --version'' in the body
375 of your report if at all possible.
377 Written by Jay Fenlason, Tom Lord, Ken Pizzini,
379 GNU sed home page: <http://www.gnu.org/software/sed/>.
380 General help using GNU software: <http://www.gnu.org/gethelp/>.
381 E-mail bug reports to: <bug-sed@gnu.org>.
382 Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.
384 Copyright \(co 2012 Free Software Foundation, Inc.
385 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
387 This is free software: you are free to change and redistribute it.
388 There is NO WARRANTY, to the extent permitted by law.
396 any of various books on \*(sd,
398 the \*(sd FAQ (http://sed.sf.net/grabbag/tutorials/sedfaq.txt),
399 http://sed.sf.net/grabbag/.
401 The full documentation for
403 is maintained as a Texinfo manual. If the
407 programs are properly installed at your site, the command
411 should give you access to the complete manual.