1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
.\" $OpeBSD$
.\"
.\" Copyright (C) Caldera International Inc. 2001-2002.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code and documentation must retain the above
.\" copyright notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed or owned by Caldera
.\" International, Inc.
.\" 4. Neither the name of Caldera International, Inc. nor the names of other
.\" contributors may be used to endorse or promote products derived from
.\" this software without specific prior written permission.
.\"
.\" USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
.\" INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE FOR ANY DIRECT,
.\" INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.\" @(#)e6 8.1 (Berkeley) 6/8/93
.\"
.SH
Special Characters
.PP
You may have noticed that things just don't work right when you used
some characters like
\*.,
.UL * ,
.UL $ ,
and others in
context searches and the substitute command.
The reason is rather complex, although the cure is simple.
Basically,
.ul
ed
treats these characters as special, with special meanings.
For instance,
.ul
in a context search or the first string of the substitute command only,
\*.
means ``any character,'' not a period, so
.P1
/x\*.y/
.P2
means ``a line with an
.UL x ,
.ul
any character,
and a
.UL y ,''
.ul
not
just ``a line with an
.UL x ,
a period, and a
.UL y .''
A complete list of the special characters
that can cause trouble is the following:
.P1
^ \*. $ [ * \e
.P2
.ul
Warning:
The backslash character
.UL \e
is special to
.ul
ed.
For safety's sake,
avoid it where possible.
If you have to use one of the special characters
in a substitute command,
you can turn off its magic meaning temporarily
by preceding it with the backslash.
Thus
.P1
s/\e\e\e\*.\e*/backslash dot star/
.P2
will change
.UL \e.*
into ``backslash dot star''.
.PP
Here is a hurried synopsis of the other special characters.
First, the circumflex
.UL ^
signifies
the beginning of a line.
Thus
.P1
/^string/
.P2
finds
.UL string
only if it is at the beginning of a line:
it will find
.P1
string
.P2
but not
.P1
the string...
.P2
The dollar-sign
.UL $
is just the opposite of the circumflex;
it means the end of a line:
.P1
/string$/
.P2
will only find an occurrence of
.UL string
that is at the end of some line.
This implies, of course,
that
.P1
/^string$/
.P2
will find only a line that contains just
.UL string ,
and
.P1
/^\*.$/
.P2
finds a line containing exactly one character.
.PP
The character
.UL . ,
as we mentioned above,
matches anything;
.P1
/x\*.y/
.P2
matches any of
.P1
x+y
x-y
x y
x\*.y
.P2
This is useful in conjunction with
.UL * ,
which is a repetition character;
.UL a*
is a shorthand for ``any number of
.UL a 's,''
so
.UL .*
matches any number of anythings.
This is used like this:
.P1
s/\*.*/stuff/
.P2
which changes an entire line,
or
.P1
s/\*.*,//
.P2
which deletes all characters in the line up to and
including the last comma.
(Since
.UL .*
finds the longest possible match,
this goes up to the last comma.)
.PP
.UL [
is used with
.UL ]
to form ``character classes'';
for example,
.P1
/[0123456789]/
.P2
matches any single digit \-
any one of the characters inside the braces
will cause a match.
This can be abbreviated to
.UL [0\-9] .
.PP
Finally, the
.UL &
is another shorthand character \-
it is used only on the right-hand part of a substitute command
where it means ``whatever was matched on the left-hand side''.
It is used to save typing.
Suppose the current line contained
.P1
Now is the time
.P2
and you wanted to put parentheses around it.
You could just retype the line, but
this is tedious.
Or you could say
.P1
s/^/(/
s/$/)/
.P2
using your knowledge of
.UL ^
and
.UL $ .
But the easiest way uses the
.UL & :
.P1
s/\*.*/(&)/
.P2
This says ``match the whole line, and replace it
by itself surrounded by parentheses.''
The
.UL &
can be used several times in a line;
consider
using
.P1
s/\*.*/&? &!!/
.P2
to produce
.P1
Now is the time? Now is the time!!
.P2
.PP
You don't have to match the whole line, of course:
if the buffer contains
.P1
the end of the world
.P2
you could type
.P1
/world/s//& is at hand/
.P2
to produce
.P1
the end of the world is at hand
.P2
Observe this expression carefully,
for it illustrates how to take advantage of
.ul
ed
to save typing.
The string
.UL /world/
found the desired line;
the shorthand
.UL //
found the same
word in the line;
and the
.UL &
saves you from typing it again.
.PP
The
.UL &
is a special character only within
the replacement text of a substitute command,
and has no special meaning elsewhere.
You can turn off the special meaning of
.UL &
by preceding it with a
.UL \e :
.P1
s/ampersand/\e&/
.P2
will convert the word ``ampersand'' into the literal symbol
.UL &
in the current line.
|