The following example shows how you can use the upto option to perform replacements in a JUNOS configuration:
Consider the hierarchy shown in Figure 16. The text string 010101 appears in three places (description sections of xe-0/0/0, xe-0/0/0.0, and fe-0/0/1). These three instances are three objects.
Figure 16: Replacement by Object

- user@host# show interfaces
- xe-0/0/0 {
- description "mkt 010101"; #1st instance in the hierarchy
-
- unit 0 {
- description "mkt 010101"; #3rd instance in the hierarchy
(child of the 1st
- instance)
- }
- }
- fe-0/0/1 {
- description "mkt 010101"; #2nd instance in the hierarchy
(sibling of the 1st
- instance)
-
- unit 0 {
-
- family inet {
- address 200.200.20.2/24;
- }
- }
- }
- [edit]
- user@host# replace pattern 01 with 02 upto
2
- [edit]
- user@host# commit
- commit complete
An upto 2 option in the replace command converts 01 to 02 for two object instances. The objects under the main interfaces xe-0/0/0 and fe-0/0/1 will be replaced first (since these are siblings in the hierarchy level). Because of the upto 2 restriction, the replace command replaces patterns in the first and second instance in the hierarchy (siblings), but not the third instance (child of the first instance).
- [edit]
- user@host# show interfaces
- xe-0/0/0 {
- description "mkt 020202"; #1st instance in the hierarchy
-
- unit 0 {
- description "mkt 010101"; #3rd instance in the hierarchy
(child of the 1st
- instance)
- }
- }
- fe-0/0/1 {
- description "mkt 020202"; #2nd instance in the hierarchy
(sibling of the 1st
- instance)
-
- unit 0 {
-
- family inet {
- address 200.200.20.2/24;
- }
- }
- }