|
|
1.1 root 1: .\" Copyright (c) 1990 Regents of the University of California.
2: .\" All rights reserved. The Berkeley software License Agreement
3: .\" specifies the terms and conditions for redistribution.
4: .\"
5: .\" @(#)sed.1 6.3 (Berkeley) 6/24/90
6: .\"
7: .TH SED 1 "%Q"
8: .AT 3
9: .SH NAME
10: sed \- stream editor
11: .SH SYNOPSIS
12: .B sed
13: [
14: .B \-n
15: ]
16: [
17: .B \-e
18: script ] [
19: .B \-f
20: sfile ] [ file ] ...
21: .SH DESCRIPTION
22: .I Sed
23: copies the named
24: .I files
25: (standard input default) to the standard output,
26: edited according to a script of commands.
27: The
28: .B \-f
29: option causes the script to be taken from file
30: .IR sfile ;
31: these options accumulate.
32: If there is just one
33: .B \-e
34: option and no
35: .BR \-f 's,
36: the flag
37: .B \-e
38: may be omitted.
39: The
40: .B \-n
41: option suppresses the default output.
42: .PP
43: A script consists of editing commands, one per line,
44: of the following form:
45: .IP
46: [address [, address] ] function [arguments]
47: .PP
48: In normal operation
49: .I sed
50: cyclically copies a line of input into a
51: .I pattern space
52: (unless there is something left after
53: a `D' command),
54: applies in sequence
55: all commands whose
56: .I addresses
57: select that pattern space,
58: and at the end of the script copies the pattern space
59: to the standard output (except under
60: .BR \-n )
61: and deletes the pattern space.
62: .PP
63: An
64: .I address
65: is either a decimal number that counts
66: input lines cumulatively across files, a `$' that
67: addresses the last line of input, or a context address,
68: `/regular expression/', in the style of
69: .IR ed (1)
70: modified thus:
71: .IP
72: The escape sequence `\en' matches a
73: newline embedded in the pattern space.
74: .PP
75: A command line with no addresses selects every pattern space.
76: .PP
77: A command line with
78: one address selects each pattern space that matches the address.
79: .PP
80: A command line with
81: two addresses selects the inclusive range from the first
82: pattern space that matches the first address through
83: the next pattern space that matches
84: the second.
85: (If the second address is a number less than or equal
86: to the line number first selected, only one
87: line is selected.)
88: Thereafter the process is repeated, looking again for the
89: first address.
90: .PP
91: Editing commands can be applied only to non-selected pattern
92: spaces by use of the negation function `!' (below).
93: .PP
94: In the following list of functions the
95: maximum number of permissible addresses
96: for each function is indicated in parentheses.
97: .PP
98: An argument denoted
99: .I text
100: consists of one or more lines,
101: all but the last of which end with `\e' to hide the
102: newline.
103: Backslashes in text are treated like backslashes
104: in the replacement string of an `s' command,
105: and may be used to protect initial blanks and tabs
106: against the stripping that is done on
107: every script line.
108: .PP
109: An argument denoted
110: .I rfile
111: or
112: .I wfile
113: must terminate the command
114: line and must be preceded by exactly one blank.
115: Each
116: .I wfile
117: is created before processing begins.
118: There can be at most 10 distinct
119: .I wfile
120: arguments.
121: .TP
122: (1)\|a\e
123: .br
124: .ns
125: .TP
126: .I text
127: .br
128: Append.
129: Place
130: .I text
131: on the output before
132: reading the next input line.
133: .TP
134: .RI (2)\|b " label"
135: Branch to the `:' command bearing the
136: .IR label .
137: If
138: .I label
139: is empty, branch to the end of the script.
140: .TP
141: (2)\|c\e
142: .br
143: .ns
144: .TP
145: .I text
146: .br
147: Change.
148: Delete the pattern space.
149: With 0 or 1 address or at the end of a 2-address range, place
150: .I text
151: on the output.
152: Start the next cycle.
153: .TP
154: (2)\|d
155: Delete the pattern space.
156: Start the next cycle.
157: .TP
158: (2)\|D
159: Delete the initial segment of the
160: pattern space through the first newline.
161: Start the next cycle.
162: .TP
163: (2)\|g
164: Replace the contents of the pattern space
165: by the contents of the hold space.
166: .TP
167: (2)\|G
168: Append the contents of the hold space to the pattern space.
169: .TP
170: (2)\|h
171: Replace the contents of the hold space by the contents of the pattern space.
172: .TP
173: (2)\|H
174: Append the contents of the pattern space to the hold space.
175: .TP
176: (1)\|i\e
177: .br
178: .ns
179: .TP
180: .I text
181: .br
182: Insert.
183: Place
184: .I text
185: on the standard output.
186: .TP
187: (2)\|n
188: Copy the pattern space to the standard output.
189: Replace the pattern space with the next line of input.
190: .TP
191: (2)\|N
192: Append the next line of input to the pattern space
193: with an embedded newline.
194: (The current line number changes.)
195: .TP
196: (2)\|p
197: Print.
198: Copy the pattern space to the standard output.
199: .TP
200: (2)\|P
201: Copy the initial segment of the pattern space through
202: the first newline to the standard output.
203: .TP
204: (1)\|q
205: Quit.
206: Branch to the end of the script.
207: Do not start a new cycle.
208: .TP
209: .RI (2)\|r " rfile"
210: Read the contents of
211: .IR rfile .
212: Place them on the output before reading
213: the next input line.
214: .TP
215: .RI (2)\|s /regular\ expression/replacement/flags
216: Substitute the
217: .I replacement
218: string for instances of the
219: .I regular expression
220: in the pattern space.
221: Any character may be used instead of `/'.
222: For a fuller description see
223: .IR ed (1).
224: .I Flags
225: is zero or more of
226: .RS
227: .TP
228: g
229: Global.
230: Substitute for all nonoverlapping instances of the
231: .I regular expression
232: rather than just the
233: first one.
234: .TP
235: p
236: Print the pattern space if a replacement was made.
237: .TP
238: .RI w " wfile"
239: Write.
240: Append the pattern space to
241: .I wfile
242: if a replacement
243: was made.
244: .RE
245: .TP
246: .RI (2)\|t " label"
247: Test.
248: Branch to the `:' command bearing the
249: .I label
250: if any
251: substitutions have been made since the most recent
252: reading of an input line or execution of a `t'.
253: If
254: .I label
255: is empty, branch to the end of the script.
256: .TP
257: .RI (2)\|w " wfile"
258: Write.
259: Append the pattern space to
260: .IR wfile .
261: .TP
262: .RI (2)\|x
263: Exchange the contents of the pattern and hold spaces.
264: .TP
265: .RI (2)\|y /string1/string2/
266: Transform.
267: Replace all occurrences of characters in
268: .I string1
269: with the corresponding character in
270: .I string2.
271: The lengths of
272: .I
273: string1
274: and
275: .I string2
276: must be equal.
277: .TP
278: .RI (2)! " function"
279: Don't.
280: Apply the
281: .I function
282: (or group, if
283: .I function
284: is `{') only to lines
285: .I not
286: selected by the address(es).
287: .TP
288: .RI (0)\|: " label"
289: This command does nothing; it bears a
290: .I label
291: for `b' and `t' commands to branch to.
292: .TP
293: (1)\|=
294: Place the current line number on the standard output as a line.
295: .TP
296: (2)\|{
297: Execute the following commands through a matching `}'
298: only when the pattern space is selected.
299: .TP
300: (0)\|
301: An empty command is ignored.
302: .TP
303: (0)\|#
304: If a \fI#\fP appears as the first character on a line of a script,
305: then that entire line is treated as a comment, with one exception.
306: If the first line of the script starts with the characters ``\fI#\fPn'',
307: then the default output will be suppressed. The rest of the line after
308: ``\fI#\fPn'' will also be ignored. A script file must contain at least one
309: non-comment line.
310: .SH SEE ALSO
311: ed(1), grep(1), awk(1), lex(1)
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.