> For the complete documentation index, see [llms.txt](https://jncia-workbook.gitbook.io/workbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jncia-workbook.gitbook.io/workbook/junos-basics/16-editing-configuration-part-3.md).

# 16) Editing Configuration (Part 3)

### Pre-Work

Load the config called **wrong.interface.cfg** using the **load\_config\_on\_nodes.py** script.

```
python3 load_config_on_nodes.py --lab_dir three-routers --config_filename wrong.interface.cfg
```

### Lab

Currently, LLDP and OSPF are fully setup in the lab. You can see that R2 and R3 are OSPF and LLDP neighbors.

```
admin@R2> show ospf neighbor                       
Address          Interface              State           ID               Pri  Dead
10.2.3.3         ge-0/0/1.0             Full            3.3.3.3          128    38

admin@R2> show lldp neighbors                      
Local Interface    Parent Interface    Chassis Id                               Port info          System Name
ge-0/0/1           -                   2c:6b:f5:c3:01:c0                        528                 R3                  

admin@R2> 
```

However, R1 has been incorrectly configured with ge-0/0/1 instead of ge-0/0/0.

**Using one line, move all ge-0/0/1 related config to ge-0/0/0.**

### Answer

<details>

<summary>Expand to reveal</summary>

We can replace all occurrences of `ge-0/0/1` with `ge-0/0/0` using the `replace pattern` tool:

```
admin@R1> configure 
Entering configuration mode

[edit]
admin@R1# replace pattern ge-0/0/1 with ge-0/0/0 

[edit]
admin@R1# show | compare 
[edit interfaces]
+   ge-0/0/0 {
+       unit 0 {
+           family inet {
+               address 10.1.2.1/24;
+           }
+           family inet6 {
+               address 2001:db8:1:2::1/64;
+           }
+       }
+   }
-   ge-0/0/1 {
-       unit 0 {
-           family inet {
-               address 10.1.2.1/24;
-           }
-           family inet6 {
-               address 2001:db8:1:2::1/64;
-           }
-       }
-   }
[edit protocols ospf area 0.0.0.0]
+     interface ge-0/0/0.0;
      interface lo0.0 { ... }
[edit protocols ospf area 0.0.0.0]
-     interface ge-0/0/1.0;
[edit protocols lldp]
+    interface ge-0/0/0;
-    interface ge-0/0/1;

[edit]
admin@R1# 
```

After committing, we should see R2 as an OSPF and LLDP neighbor:

```
admin@R1> show ospf neighbor     
Address          Interface              State           ID               Pri  Dead
10.1.2.2         ge-0/0/0.0             Full            2.2.2.2          128    34

admin@R1> show lldp neighbors    
Local Interface    Parent Interface    Chassis Id                               Port info          System Name
ge-0/0/0           -                   2c:6b:f5:27:1c:c0                        528                 R2                  
```

</details>

### Explanation

<details>

<summary>Expand to reveal</summary>

The `replace pattern` tool is a very useful feature that allows us to easily move interface configuration. Just like it sounds, it finds all occurrences of the given pattern and replaces it with the new pattern. (Basically "find and replace").

\
Without this, we would have had to issue many different `delete` and `set` statements. The `replace pattern` tool can save tons of time and avoid mistakes.

\
Other tools to be aware of are:

* `copy`
  * `copy interfaces ge-0/0/0 to interfaces ge-0/0/1`
* `wildcard range`
  * `wildcard range set interfaces ge-0/0/[0-10] unit 0 family ethernet-switching port-mode access`
* `wildcard delete`
  * `wildcard delete interfaces ge-0/0/0 unit *`

</details>

### Further Reading

<https://supportportal.juniper.net/s/article/Junos-How-to-use-the-replace-pattern-command-to-replace-multiple-lines-of-configuration-without-having-to-delete-and-re-add>

<https://www.juniper.net/documentation/us/en/software/junos/cli-reference/topics/ref/command/copy.html>

<https://supportportal.juniper.net/s/article/EX-QFX-Wildcard-range-commands-for-EX-switches>

<https://www.juniper.net/documentation/us/en/software/junos/cli-reference/topics/ref/command/wildcard.html>
