[Contents] [Prev] [Next] [Index] [Report an Error]

Using Global Replace in a JUNOS Configuraton

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.

user@host# replace pattern pattern1 with pattern2 <upto n>

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.

Common Regular Expressions to Use with the replace Command shows some common regular expressions you can use with the replace command.


[Contents] [Prev] [Next] [Index] [Report an Error]