XG Series User's Guide Chapter 2 Using the CLI
Using the CLI
51
Replacing command strings
By entering a single-replacement specifier (:s) or all-replacement specifier (:gs) following a history specifier and
replacement specifier, you can replace the target string and re-execute the command string.
A single-replacement specifier replaces the first matching string only, while an all-replacement specifier replaces all
matching strings.
The replacement target string and replacement string are specified as with string replacement for the preceding command;
however, arbitrary characters (@, #, %, &, ~, =, _, etc.) may be used as delimiters. You can successively enter a single-
replacement specifier, all-replacement specifier, and display specifier.
The table below lists specifiers and operations. This example uses "/" as a delimiter.
(A: replacement target string, B: replacement string, C: additional string)
A command execution example is shown below.
zCommand
Command Operation
:s/A/B/ Replace only the first instance of A with B and execute the command string.
:ps/A/B/ Replace only the first instance of A with B and display the command string.
:s/A/B/C Replace only the first instance of A with B, add C to the command string, and execute it.
:ps/A/B/C Replace only the first instance of A with B, add C to the command string, and display it.
:gs/A/B/ Replace all instances of A with B and execute the command string.
:pgs/A/B/ Replace all instances of A with B and display the command string.
:gs/A/B/C Replace all instances of A with B, add C to the command string, and execute it.
:pgs/A/B/C Replace all instances of A with B, add C to the command string, and display it.
:s/A// Delete only the first instance of A and execute the command string.
:ps/A// Delete only the first instance of A and display the command string.
:s/A//C Delete only the first instance of A, add C to the command string, and execute it.
:ps/A//C Delete only the first instance of A, add C to the command string, and display it.
:gs/A// Delete all instances of A and execute the command string.
:pgs/A// Delete all instances of A and display the command string.
:gs/A//C Delete all instances of A, add C to the command string, and execute it.
:pgs/A//C Delete all instances of A, add C to the command string, and display it.
:s/A1/B1/:gs/A2/B2/:p Replace only the first instance of A1 with B1, replace all instances of A2 with B2, and display the
command string.
# lan 0 ip address 192.168.0.1/24 3
# !!:gs/0/1/:p (Replace all instances of 0 with 1 and display the command string.)
lan 1 ip address 192.168.1.1/24 3
# !! (Re-execute the last command to run.)
lan 1 ip address 192.168.1.1/24 3
Note
When entering a command with the command history function, you can omit the last delimiter (/, ^, etc.) at the end of the
command line. However, when the last delimiter is omitted, you cannot specify a display specifier (:p), additional history
specifier, or additional string.