Substituting at the beginning or end of a line, Using a context search, Deleting lines—the d (delete) subcommand – HP NonStop G-Series User Manual
Page 175

Substituting at the Beginning or End of a Line
Two special characters let you make substitutions at the beginning or end of a line:
Makes a substitution at the beginning of the line.
^
(circumflex)
Makes a substitution at the end of the line. (In this context,
the $ character does not stand for the last line in the buffer.)
$
(dollar sign)
To make a substitution at the beginning of a line, use the s/^/newstring subcommand. In the
following example, the first s subcommand adds the string “Remember” to the start of line number
1. The second s subcommand adds the string “adding” to the start of line 2:
1s/^/Remember, /p
Remember, The only way to quit
2s/^/adding/p
adding text is to type a
To make a substitution at the end of a line, use a subcommand of the form s/$/newstring. In
the following example, the s subcommand adds the string “Then press Enter.” to the end of line
number 4:
4s/$/ Then press Enter./p
a period. Then press Enter.
Notice that the substituted string includes two blanks before the word “Then” to separate the two
sentences.
Using a Context Search
If you do not know the number of the line you want to change, you can locate it with a context
search. See
for more information on context searches.
For convenience, you can combine a context search and a substitution into a single subcommand:
/string_to_find/s/oldstring/newstring/
.
In the following example, ed locates the line that contains the string “, The” and replaces that string
with “, the”:
/, The/s/, The/, the/p
Remember, the only way to quit
Also, you can use the search string as the string to be replaced with a subcommand of the form
/string_to_find/s//newstring/
. In the following example, ed locates the line that contains
the string “cONtains ONly”, replaces that string with “contains only”, and displays the changed
line:
/cONtains ONly/s//contains only/p
line that contains only
Deleting Lines—The d (Delete) Subcommand
Use the d (delete) subcommand to remove one or more lines from the buffer. The general form of
the d subcommand is the following:
starting_line,ending_lined
After you delete lines, ed sets the current line to the first line following the lines that were deleted.
If you delete the last line from the buffer, the last remaining line in the buffer becomes the current
line. After a deletion, ed renumbers the remaining lines in the buffer.
To delete lines from the buffer, do the following:
•
To delete the current line, enter:
d
•
To delete line number n from the buffer, enter:
Deleting Lines—The d (Delete) Subcommand
175