Related Documentation
- EX, J, M, MX, PTX, T Series
- Common Regular Expressions to Use with the replace Command
- Example: Using Global Replace in a Junos Configuration—Using the \n Back Reference
- Example: Using Global Replace in a Junos Configuration—Replacing an Interface Name
- Using Wildcard Characters in Interface Names
- Using Keyboard Sequences to Move Around and Edit the Junos OS CLI
Using Global Replace in a Junos Configuration
You can make global changes to variables and identifiers in a Junos configuration by using the replace configuration mode command. This command replaces a pattern in a configuration with another pattern. For example, you can use this command to find and replace all occurrences of an interface name when a PIC is moved to another slot in the router.
pattern pattern1 is a text string or regular expression that defines the identifiers and values you want to replace in the configuration.
pattern2 is a text string or regular expression that replaces the identifiers and values located with pattern1.
Juniper Networks uses standard UNIX-style regular expression syntax (as defined in POSIX 1003.2). If the regular expression contains spaces, operators, or wildcard characters, enclose the expression in quotation marks. Greedy qualifiers (match as much as possible) are supported. Lazy qualifiers (match as little as possible) are not.
The upto n option specifies the number of objects replaced. The value of n controls the total number of objects that are replaced in the configuration (not the total number of times the pattern occurs). Objects at the same hierarchy level (siblings) are replaced first. Multiple occurrences of a pattern within a given object are considered a single replacement. For example, if a configuration contains a 010101 text string, the command replace pattern 01 with pattern 02 upto 2 replaces 010101 with 020202 (instead of 020201). Replacement of 010101 with 020202 is considered a single replacement (n = 1), not three separate replacements (n =3).
If you do not specify an upto option, all identifiers and values in the configuration that match pattern1 are replaced.
The replace command is available in configuration mode at any hierarchy level. All matches are case-sensitive.
Related Documentation
- EX, J, M, MX, PTX, T Series
- Common Regular Expressions to Use with the replace Command
- Example: Using Global Replace in a Junos Configuration—Using the \n Back Reference
- Example: Using Global Replace in a Junos Configuration—Replacing an Interface Name
- Using Wildcard Characters in Interface Names
- Using Keyboard Sequences to Move Around and Edit the Junos OS CLI
Published: 2012-11-27
Related Documentation
- EX, J, M, MX, PTX, T Series
- Common Regular Expressions to Use with the replace Command
- Example: Using Global Replace in a Junos Configuration—Using the \n Back Reference
- Example: Using Global Replace in a Junos Configuration—Replacing an Interface Name
- Using Wildcard Characters in Interface Names
- Using Keyboard Sequences to Move Around and Edit the Junos OS CLI