source: trunk/minix/man/man1/sed.1@ 15

Last change on this file since 15 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 9.7 KB
Line 
1.TH sed 1 "November 19, 1995"
2.SH NAME
3sed \- the stream editor
4.SH SYNOPSIS
5.B sed
6.RB [ \-n ]
7.RB [ \-g ]
8.RB [ \-e
9.IR script ]
10.RB [ \-f
11.IR sfile ]
12.RI [ file " ...]"
13.SH DESCRIPTION
14Sed copies the named files (standard input default) to the standard
15output, edited according to a script of commands.
16.P
17An
18.B \-e
19option supplies a single edit command from the next argument;
20if there are several of these they are executed in the order in which
21they appear. If there is just one
22.B \-e
23option and no
24.BR \-f "'s,"
25the
26.B \-e
27flag may be omitted.
28.P
29An
30.B \-f
31option causes commands to be taken from the file "sfile"; if
32there are several of these they are executed in the order in which
33they appear;
34.B \-e
35and
36.B \-f
37commands may be mixed.
38.P
39The
40.B \-g
41option causes
42.B sed
43to act as though every substitute command
44in the script has a
45.B g
46suffix.
47.P
48The
49.B \-n
50option suppresses the default output.
51.P
52A script consists of commands, one per line, of the following form:
53.PP
54 [address [, address] ] function [arguments]
55.PP
56Normally
57.B sed
58cyclically copies a line of input into a current text
59buffer, then applies all commands whose addresses select the buffer in
60sequence, then copies the buffer to standard output and clears it.
61.P
62The
63.B \-n
64option suppresses normal output (so that only
65.B p
66and
67.B w
68output is done). Also, some commands
69.RB ( n ,
70.BR N )
71do their own line reads, and some others
72.RB ( d ,
73.BR D )
74cause all commands following in the script to be skipped (the
75.B D
76command also suppresses the clearing of the current text
77buffer that would normally occur before the next cycle).
78.P
79It is also helpful to know that there's a second buffer (called the `hold
80space' that can be copied or appended to or from or swapped with
81the current text buffer.
82.P
83An address is: a decimal numeral (which matches the line it numbers where line
84numbers start at 1 and run cumulatively across files), or a `$' that addresses
85the last line of input, or a context address, which is a `/regular
86expression/', in the style of
87.BR ed (1)
88modified thus:
89.P
90.TP 5
91(1)
92The escape sequence `\en' matches a newline embedded in the buffer,
93and `\et' matches a tab.
94.TP 5
95(2)
96A command line with no addresses selects every buffer.
97.TP 5
98(3)
99A command line with one address selects every buffer that matches
100that address.
101.TP 5
102(4)
103A command line with two addresses selects the inclusive range from
104the first input buffer that matches the first address through the
105next input buffer that matches the second. (If the second address
106is a number less than or equal to the line number first selected,
107only one line is selected.) Once the second address is matched
108.B sed
109starts looking for the first one again; thus, any number of these
110ranges will be matched.
111.P
112The negation operator '!' can prefix a command to apply it to every
113line not selected by the address(es).
114.P
115In the following list of functions, the maximum number of addresses
116permitted for each function is indicated in parentheses.
117.P
118An argument denoted "text" consists of one or more lines, with all
119but the last ending with `\e' to hide the newline.
120.P
121Backslashes in text are treated like backslashes in the replacement
122string of an
123.B s
124command and may be used to protect initial whitespace (blanks and tabs)
125against the stripping that is done on every line of the script.
126.P
127An argument denoted "rfile" or "wfile" must be last on the command
128line. Each wfile is created before processing begins. There can be at
129most 10 distinct wfile arguments.
130.ta +\w'nm'u +\w'"command"m'u
131.TP 5
132a "text" (1)
133Append. Place text on output before reading the next input line.
134.TP 5
135b "label" (2)
136Branch to the `:' command bearing the label. If no label is given,
137branch to the end of the script.
138.TP 5
139c "text" (2)
140Change. Delete the current text buffer. With 0 or 1 address, or at
141the end of a 2-address range, place text on the output. Start the next
142cycle.
143.TP 5
144d (2)
145Delete the current text buffer. Start the next cycle.
146.TP 5
147D (2)
148Delete the first line of the current text buffer (all chars up to the
149first newline). Start the next cycle.
150.TP 5
151g (2)
152Replace the contents of the current text buffer with the contents of
153the hold space.
154.TP 5
155G (2)
156Append the contents of the hold space to the current text buffer.
157.TP 5
158h (2)
159Copy the current text buffer into the hold space.
160.TP 5
161H (2)
162Append a copy of the current text buffer to the hold space.
163.TP 5
164i "text" (1)
165Insert. Place text on the standard output.
166.TP 5
167l (2)
168List. Sends the pattern space to standard output. A "w" option may
169follow as in the
170.B s
171command below. Non-printable characters expand to:
172.sp .4v
173.in +3
174.nf
175.ta +\w'xxxn'u +\w'nnnn'u +\w'backspace 'u
176\eb \-\- backspace (ASCII 08)
177\et \-\- tab (ASCII 09)
178\en \-\- newline (ASCII 10)
179\er \-\- return (ASCII 13)
180\ee \-\- escape (ASCII 27)
181\exx \-\- the ASCII character corresponding to 2 hex digits xx.
182.fi
183.in -3
184.ta +\w'nm'u +\w'"command"m'u
185.TP 5
186n (2)
187Copy the current text buffer to standard output. Read the next line
188of input into it.
189.TP 5
190N (2)
191Append the next line of input to the current text buffer, inserting
192an embedded newline between the two. The current line number changes.
193.TP 5
194p (2)
195Print. Copy the current text buffer to the standard output.
196.TP 5
197P (2)
198Copy the first line of the current text buffer (all chars up to the
199first newline) to standard output.
200.TP 5
201q (1)
202Quit. Branch to the end of the script. Do not start a new cycle.
203.TP 5
204r "rfile" (1)
205Read the contents of rfile. Place them on the output before reading
206the next input line.
207.TP 5
208s /regular-expression/replacement/flags\0\0\0\0\0\0(2)
209Substitute the replacement for instances of the regular expression
210in the current text buffer. Any character may be used instead of `/'.
211For a fuller description see ed (1).
212Flags is zero or more of the following:
213.sp .4v
214.ta +\w'gm'u +\w'nnm'u
215.in +\w'gmnnm'u
216.ti -\w'gmnnm'u
217g \-\- Global. Substitute for all nonoverlapping instances of
218the string rather than just the first one.
219.sp .4v
220.ti -\w'gmnnm'u
221p \-\- Print the pattern space if a replacement was made.
222.sp .4v
223.ti -\w'gmnnm'u
224w \-\- Write. Append the current text buffer to a file argument
225as in a w command if a replacement is made. Standard output is used if no
226file argument is given
227.in -\w'gmnnm'u
228.ta +\w'nm'u +\w'"command"m'u
229.TP 5
230t "label" (2)
231Branch-if-test. Branch to the
232.B :
233command with the given label if any
234substitutes have been made since the most recent read of an input line
235or execution of a
236.B t
237or
238.BR T .
239If no label is given, branch to the end of the script.
240.TP 5
241T "label" (2)
242Branch-on-error. Branch to the
243.B :
244command with the given label if no substitutes have succeeded since the
245last input line or
246.B t
247or
248.B T
249command. Branch to the end of the script if no label is given.
250.TP 5
251w "wfile" (2)
252Write. Append the current text buffer to wfile.
253.TP 5
254W "wfile" (2)
255Write first line. Append first line of the current text buffer
256to wfile.
257.TP 5
258x (2)
259Exchange the contents of the current text buffer and hold space.
260.TP 5
261y /string1/string2/\0\0\0\0\0\0(2)
262Translate. Replace each occurrence of a character in string1 with
263the corresponding character in string2. The lengths of these strings
264must be equal.
265.TP 5
266! "command" (2)
267All-but. Apply the function (or group, if function is
268.BR { )
269only to lines not selected by the address(es).
270.TP 5
271: "label" (0)
272This command does nothing but hold a label for
273.B b
274and
275.B t
276commands to branch to.
277.TP 5
278= (1)
279Place the current line number on the standard output as a line.
280.TP 5
281{ (2)
282Execute the following commands through a matching `}' only when the
283current line matches the address or address range given.
284.P
285An empty command is ignored.
286.P
287.SH PORTABILITY
288This tool was reverse-engineered from BSD 4.1 UNIX
289.BR sed ,
290and (as far
291as the author's knowledge and tests can determine) is compatible with
292it. All documented features of BSD 4.1 sed are supported.
293.P
294One undocumented feature (a leading 'n' in the first comment having
295the same effect as an
296.B \-n
297command-line option) has been omitted.
298.P
299The following bugs and limitations have been fixed:
300.TP 5
301\(bu
302There is no hidden length limit (40 in BSD sed) on
303.B w
304file names.
305.TP 5
306\(bu
307There is no limit (8 in BSD sed) on the length of labels.
308.TP 5
309\(bu
310The exchange command now works for long pattern and hold spaces.
311.P
312The following enhancements to existing commands have been made:
313.TP 5
314\(bu
315.BR a ,
316.B i
317commands don't insist on a leading backslash-\en in the text.
318.TP 5
319\(bu
320.BR r ,
321.B w
322commands don't insist on whitespace before the filename.
323.TP 5
324\(bu
325The
326.BR g ,
327.B p
328and
329.B P
330options on
331.B s
332commands may be given in any order.
333.P
334Some enhancements to regular-expression syntax have been made:
335.TP 5
336\(bu
337\et is recognized in REs (and elsewhere) as an escape for tab.
338.TP 5
339\(bu
340In an RE, + calls for 1..n repeats of the previous pattern.
341.P
342The following are completely new features:
343.TP 5
344\(bu
345The
346.B l
347command (list, undocumented and weaker in BSD)
348.TP 5
349\(bu
350The
351.B W
352command (write first line of pattern space to file).
353.TP 5
354\(bu
355The
356.B T
357command (branch on last substitute failed).
358.TP 5
359\(bu
360Trailing comments are now allowed on command lines.
361.P
362In addition,
363.BR sed "'s"
364error messages have been made more specific and informative.
365.P
366The implementation is also significantly smaller and faster than
367BSD 4.1 sed. It uses only the standard I/O library and exit(3).
368.P
369.SH NOTE
370.P
371This is a freeware component of the GNU and MINIX operating systems.
372The user is hereby granted permission to use, modify, reproduce and
373distribute it subject to the following conditions:
374.P
3751. The authorship notice appearing in each source file may not be
376altered or deleted.
377.P
3782. The object form may not be distributed without source.
379.P
380.SH SEE ALSO
381.P
382.BR cgrep (1),
383.BR fgrep (1),
384.BR grep (1),
385.BR lex (1),
386.BR regexp (5),
387.BR awk (9).
388.P
389.SH AUTHOR
390Eric S. Raymond <esr@snark.thyrsus.com>
Note: See TracBrowser for help on using the repository browser.