Hp NonStop G-Series Instrukcja Użytkownika Strona 174

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 213
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 173
where n is the number of the line on which the substitution is to be made. In the following example,
the s subcommand moves to line number 1, replaces the string “stop” with the string “quit”, and
displays the new line:
1s/stop/quit/p
The only way to quit
The 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 Multiple Lines
To make a substitution on multiple lines, use a subcommand of the following form:
n,ms/oldstring/newstring/
where n is the line number of the first line of the group and m is the line number of the last line.
In the following example, the s subcommand replaces the first occurrence of the string “to” with
the string “TO” on every line in the buffer:
1,$s/to/TO/
1,$p
The only way TO quit
adding text is TO type a
line that contains only
a period.
The 1,$p subcommand displays the contents of the buffer, which lets you verify that the substitutions
were made.
Substituting Every Occurrence of a String
Ordinarily, the s (substitute) subcommand changes only the first occurrence of a string on a given
line. However, the g (global) operator lets you change every occurrence of a string on a line or
in a group of lines.
To make a global substitution on a single line, use a subcommand of the following form:
ns/oldstring/newstring/g
In the following example, 3s/on/ON/gp changes each occurrence of the string “on” to “ON” in
line 3 and displays the new line:
3s/on/ON/gp
line that cONtains ONly
To make a global substitution on multiple lines, specify the group of lines with a subcommand of
the form:
n,ms/oldstring/newstring/g
In the following example, 1,$s/TO/to/gp changes the string “TO” into the string “to” in every
line in the buffer:
1,$s/TO/to/gp
The only way to quit
adding text is to type a
line that cONtains ONly
a period.
Removing Characters
You can use the s (substitute) subcommand to remove a string of characters (that is, to replace the
string with nothing). To remove characters, use a subcommand of the form s/oldstring// with
no space between the // (last two slashes).
In the following example, ed removes the string “adding” from line number 2 and then displays
the changed line:
2s/adding// p
text is to type a
174 The ed Editor
Przeglądanie stron 173
1 2 ... 169 170 171 172 173 174 175 176 177 178 179 ... 212 213

Komentarze do niniejszej Instrukcji

Brak uwag