Modifying a configuration often requires you to search for an identifier or value and replace it with another. For example, suppose you change the IP address of the ge-0/0/1 interface and need to update it throughout the configuration.
The replace configuration mode command allows you to find and replace identifiers or values without manually searching the configuration hierarchy on the router or uploading the configuration file into a text editor. The replace command supports regular expressions, and allows you to perform find and replace operations using complex search criteria. For example, you can use regular expressions to find and replace all instances of IP addresses starting with 192.
![]() |
Note: The search-and-replace operation of the replace command is case-sensitive, and case-sensitivity cannot be disabled. In addition, the replace command does not support lazy quantifiers in regular expressions. |
You can use the replace command at any level in the configuration hierarchy. Identifiers or values specified are replaced from that level downwards in the configuration hierarchy. For example, if you use the replace command at the [edit interfaces] hierarchy level to change an IP address from 10.1.1.1 to 10.2.1.1, the changes are made in the configuration hierarchy under interfaces, but not throughout the configuration.
To replace an identifier or value in the configuration, enter the replace command as follows:
-
replace pattern identifier 1 with identifier
2 upto number
The upto option does not specify the number of instances of the pattern to be replaced, but the number of configuration objects within which the search-and-replace operation is performed. For example, if you issue the replace command at the [edit interfaces] hierarchy level, and specify 3 for upto, the search-and-replace operation is performed within the first three configuration objects under interfaces—for example, ge-0/0/0, e1-5/0/1, and lo0.
If you do not specify the upto option, all occurrences of the specified pattern are replaced from the configuration hierarchy level downwards.
For more information, see the JUNOS CLI User Guide.
The examples in Table 15 illustrate ways in which you can use the replace command.
Table 15: Sample replace Commands