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