OSDN Git Service

sed: Update original to GNU sed 4.2.2
[linuxjm/jm.git] / manual / GNU_sed / original / man1 / sed.1
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"
3 .SH NAME
4 sed \- stream editor for filtering and transforming text
5 .SH SYNOPSIS
6 .B sed
7 [\fIOPTION\fR]... \fI{script-only-if-no-other-script} \fR[\fIinput-file\fR]...
8 .SH DESCRIPTION
9 .ds sd \fIsed\fP
10 .ds Sd \fISed\fP
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
21 editors.
22 .HP
23 \fB\-n\fR, \fB\-\-quiet\fR, \fB\-\-silent\fR
24 .IP
25 suppress automatic printing of pattern space
26 .HP
27 \fB\-e\fR script, \fB\-\-expression\fR=\fIscript\fR
28 .IP
29 add the script to the commands to be executed
30 .HP
31 \fB\-f\fR script-file, \fB\-\-file\fR=\fIscript\-file\fR
32 .IP
33 add the contents of script-file to the commands to be executed
34 .HP
35 \fB\-\-follow\-symlinks\fR
36 .IP
37 follow symlinks when processing in place
38 .HP
39 \fB\-i[SUFFIX]\fR, \fB\-\-in\-place\fR[=\fISUFFIX\fR]
40 .IP
41 edit files in place (makes backup if SUFFIX supplied)
42 .HP
43 \fB\-l\fR N, \fB\-\-line\-length\fR=\fIN\fR
44 .IP
45 specify the desired line-wrap length for the `l' command
46 .HP
47 \fB\-\-posix\fR
48 .IP
49 disable all GNU extensions.
50 .HP
51 \fB\-r\fR, \fB\-\-regexp\-extended\fR
52 .IP
53 use extended regular expressions in the script.
54 .HP
55 \fB\-s\fR, \fB\-\-separate\fR
56 .IP
57 consider files as separate rather than as a single continuous
58 long stream.
59 .HP
60 \fB\-u\fR, \fB\-\-unbuffered\fR
61 .IP
62 load minimal amounts of data from the input files and flush
63 the output buffers more often
64 .HP
65 \fB\-z\fR, \fB\-\-null\-data\fR
66 .IP
67 separate lines by NUL characters
68 .TP
69 \fB\-\-help\fR
70 display this help and exit
71 .TP
72 \fB\-\-version\fR
73 output version information and exit
74 .PP
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.
79 .PP
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.
89 .SS
90 Zero-address ``commands''
91 .TP
92 .RI :\  label
93 Label for
94 .B b
95 and
96 .B t
97 commands.
98 .TP
99 .RI # comment
100 The comment extends until the next newline (or the end of a
101 .B -e
102 script fragment).
103 .TP
104 }
105 The closing bracket of a { } block.
106 .SS
107 Zero- or One- address commands
108 .TP
109 =
110 Print the current line number.
111 .TP
112 a \e
113 .TP
114 .I text
115 Append
116 .IR text ,
117 which has each embedded newline preceded by a backslash.
118 .TP
119 i \e
120 .TP
121 .I text
122 Insert
123 .IR text ,
124 which has each embedded newline preceded by a backslash.
125 .TP
126 q [\fIexit-code\fR]
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.
131 .TP
132 Q [\fIexit-code\fR]
133 Immediately quit the \*(sd script without processing
134 any more input.  This is a GNU extension.
135 .TP
136 .RI r\  filename
137 Append text read from
138 .IR filename .
139 .TP
140 .RI R\  filename
141 Append a line read from
142 .IR filename .
143 Each invocation of the command reads a line from the file.
144 This is a GNU extension.
145 .SS
146 Commands which accept address ranges
147 .TP
148 {
149 Begin a block of commands (end with a }).
150 .TP
151 .RI b\  label
152 Branch to
153 .IR label ;
154 if
155 .I label
156 is omitted, branch to end of script.
157 .TP
158 c \e
159 .TP
160 .I text
161 Replace the selected lines with
162 .IR text ,
163 which has each embedded newline preceded by a backslash.
164 .TP
165 d
166 Delete pattern space.
167 Start next cycle.
168 .TP
169 D
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.
174 .TP
175 h H
176 Copy/append pattern space to hold space.
177 .TP
178 g G
179 Copy/append hold space to pattern space.
180 .TP
181 l
182 List out the current line in a ``visually unambiguous'' form.
183 .TP
184 .RI l\  width
185 List out the current line in a ``visually unambiguous'' form,
186 breaking it at
187 .I width
188 characters.  This is a GNU extension.
189 .TP
190 n N
191 Read/append the next line of input into the pattern space.
192 .TP
193 p
194 Print the current pattern space.
195 .TP
196 P
197 Print up to the first embedded newline of the current pattern space.
198 .TP
199 .RI s/ regexp / replacement /
200 Attempt to match
201 .I regexp
202 against the pattern space.
203 If successful, replace that portion matched
204 with
205 .IR replacement .
206 The
207 .I replacement
208 may contain the special character
209 .B &
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
213 .IR regexp .
214 .TP
215 .RI t\  label
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
219 .IR label ;
220 if
221 .I label
222 is omitted, branch to end of script.
223 .TP
224 .RI T\  label
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
228 .IR label ;
229 if
230 .I label
231 is omitted, branch to end of script.  This is a GNU
232 extension.
233 .TP
234 .RI w\  filename
235 Write the current pattern space to
236 .IR filename .
237 .TP
238 .RI W\  filename
239 Write the first line of the current pattern space to
240 .IR filename .
241 This is a GNU extension.
242 .TP
243 x
244 Exchange the contents of the hold and pattern spaces.
245 .TP
246 .RI y/ source / dest /
247 Transliterate the characters in the pattern space which appear in
248 .I source
249 to the corresponding character in
250 .IR dest .
251 .SH
252 Addresses
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
260 the second address.
261 Three things to note about address ranges:
262 the syntax is
263 .IR addr1 , addr2
264 (i.e., the addresses are separated by a comma);
265 the line which
266 .I addr1
267 matched will always be accepted,
268 even if
269 .I addr2
270 selects an earlier line;
271 and if
272 .I addr2
273 is a
274 .IR regexp ,
275 it will not be tested against the line that
276 .I addr1
277 matched.
278 .PP
279 After the address (or address-range),
280 and before the command, a
281 .B !
282 may be inserted,
283 which specifies that the command shall only be
284 executed if the address (or address-range) does
285 .B not
286 match.
287 .PP
288 The following address types are supported:
289 .TP
290 .I number
291 Match only the specified line
292 .IR number
293 (which increments cumulatively across files, unless the
294 .B -s
295 option is specified on the command line).
296 .TP
297 .IR first ~ step
298 Match every
299 .IR step 'th
300 line starting with line
301 .IR first .
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.
305 .I first
306 can be zero; in this case, \*(sd operates as if it were equal to
307 .IR step .
308 (This is an extension.)
309 .TP
310 $
311 Match the last line.
312 .TP
313 .RI / regexp /
314 Match lines matching the regular expression
315 .IR regexp .
316 .TP
317 .BI \fR\e\fPc regexp c
318 Match lines matching the regular expression
319 .IR regexp .
320 The
321 .B c
322 may be any character.
323 .PP
324 GNU \*(sd also supports some special 2-address forms:
325 .TP
326 .RI 0, addr2
327 Start out in "matched first address" state, until
328 .I addr2
329 is found.
330 This is similar to
331 .RI 1, addr2 ,
332 except that if
333 .I addr2
334 matches the very first line of input the
335 .RI 0, addr2
336 form will be at the end of its range, whereas the
337 .RI 1, addr2
338 form will still be at the beginning of its range.
339 This works only when
340 .I addr2
341 is a regular expression.
342 .TP
343 .IR addr1 ,+ N
344 Will match
345 .I addr1
346 and the
347 .I N
348 lines following
349 .IR addr1 .
350 .TP
351 .IR addr1 ,~ N
352 Will match
353 .I addr1
354 and the lines following
355 .I addr1
356 until the next line whose input line number is a multiple of
357 .IR N .
358 .SH "REGULAR EXPRESSIONS"
359 POSIX.2 BREs
360 .I should
361 be supported, but they aren't completely because of performance
362 problems.
363 The
364 .B \en
365 sequence in a regular expression matches the newline character,
366 and similarly for
367 .BR \ea ,
368 .BR \et ,
369 and other sequences.
370 .SH BUGS
371 .PP
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.
376 .SH AUTHOR
377 Written by Jay Fenlason, Tom Lord, Ken Pizzini,
378 and Paolo Bonzini.
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.
383 .SH COPYRIGHT
384 Copyright \(co 2012 Free Software Foundation, Inc.
385 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
386 .br
387 This is free software: you are free to change and redistribute it.
388 There is NO WARRANTY, to the extent permitted by law.
389 .SH "SEE ALSO"
390 .BR awk (1),
391 .BR ed (1),
392 .BR grep (1),
393 .BR tr (1),
394 .BR perlre (1),
395 sed.info,
396 any of various books on \*(sd,
397 .na
398 the \*(sd FAQ (http://sed.sf.net/grabbag/tutorials/sedfaq.txt),
399 http://sed.sf.net/grabbag/.
400 .PP
401 The full documentation for
402 .B sed
403 is maintained as a Texinfo manual.  If the
404 .B info
405 and
406 .B sed
407 programs are properly installed at your site, the command
408 .IP
409 .B info sed
410 .PP
411 should give you access to the complete manual.