Changing the direction of a search, Making substitutions—the s (substitute) subcommand, Substituting on the current line – HP NonStop G-Series User Manual

Page 173: Substituting on a specific line

Advertising
background image

The context search begins on the first line before the current line and locates the first line that
contains the string appending. That line becomes the current line. If ed searches the entire buffer
without finding the string, it stops the search at the current line and displays the message ?.
Once you have searched backward for a string, you can search backward for the same string
again by entering just ??.

Changing the Direction of a Search

You can change the direction of a search for a particular string by using the / (slash) and ?
(question mark) search characters alternately:

/only/
line that contains only
??
The only way to stop

If you go too far while searching for a character string, it is convenient to be able to change the
direction of your search.

Making Substitutions—The s (Substitute) Subcommand

Use the s (substitute) subcommand to replace one character string (a group of one or more
characters) with another. The s subcommand works with one or more lines at a time, and it is
especially useful for correcting typing or spelling errors.
To make substitutions, do one of the following:

To substitute newstring for oldstring, at the first occurrence of oldstring in the current
line, enter:

s/oldstring/newstring/

To substitute newstring for oldstring, at the first occurrence of oldstring on line
number n, enter:

ns/oldstring/newstring/

To substitute newstring for oldstring, at the first occurrence of oldstring in each of
the lines n through m, enter:

n,ms/oldstring/newstring/

Substituting on the Current Line

To make a substitution on the current line, first make sure that the line you want to change is the
current line. In the following example, the /appending/ (search) subcommand locates the line
to be changed. Then the s/appending/adding text/p (substitute) subcommand substitutes
the string, “adding text” for the string “appending” on the current line. The p (print) subcommand
displays the changed line.

/appending/
appending is to type a
s/appending/adding text/p
adding text is to type a

NOTE:

For convenience, you can add the p subcommand to the s subcommand (for example,

s/appending/adding text/p

). This saves you from having to type a separate p subcommand

to see the result of the substitution.

A simple s subcommand changes only the first occurrence of the string on a given line. To learn
how to change all occurrences of a string on the line, see

“Substituting Every Occurrence of a

String” (page 174)

.

Substituting on a Specific Line

To make a substitution on a specific line, use a subcommand of the following form:

ns/oldstring/newstring/

Making Substitutions—The s (Substitute) Subcommand

173

Advertising
This manual is related to the following products: