cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements

244
Views
0
Helpful
1
Replies

grep cisco interfaces without any configuration

This is sample of Cisco Switch configuration file. If the interface is not in use, it should be in shutdown mode.

config.txt

!
interface GigabitEthernet0/0
 shutdown
!
interface GigabitEthernet0/1
!
interface GigabitEthernet0/2
 shutdown
!
interface GigabitEthernet0/3 
!

Therefore, I would like to grep any interfaces without any configuration and no shutdown in it.

Desired Output

!
interface GigabitEthernet0/1
!
!
interface GigabitEthernet0/3 
!

Can I do something like grep interface.*[0-9] config.txt where the line before and after it must match !

Here are a few of my attempts, but none of them producing the output that I wanted.

grep interface.*[0-9] config.txt
grep -C1 interface.*[0-9] config.txt

If there is a better solution then grep, please let me know.

1 REPLY 1
Francesco Molino
VIP Mentor

Hi
On your linux machine, install the package pcregrep if not already there.
Then run the following command:
grep -Pzo "!(\n)|interface.*[0-9](.|\n)!(\n)" config.txt

You'll get the following output:
!
!
interface GigabitEthernet0/1
!
!
interface GigabitEthernet0/3
!

Thanks
Francesco
PS: Please don't forget to rate and select as validated answer if this answered your question
This widget could not be displayed.