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