0

I need help working with router config backup database. I need to get a list of interfaces that don't have vrf or shutdown in their configuration. I get the list of all interfaces config passing the config file through awk '/^interface/,/!/'. This gives me the output below:

interface TenGigE0/3/0/0
 description 
 service-policy output QOS
 ipv4 mtu 1500
 ipv4 address 13.24.15.3 255.255.255.252
 carrier-delay up 3000 down 0
 load-interval 30
 dampening
!
interface TenGigE0/3/0/1
 description Link To 
!
interface TenGigE0/3/0/1.302
 description 
 vrf 1671
 ipv4 address 13.24.14.11 255.255.255.254
 encapsulation dot1q 302

Now, i am stuck trying to exclude the interfaces that contain vrf line. What i was trying to do is to grep for vrf, and when there is a match, remove the line that contains the word "interface" above. Unfortunately with no luck. Maybe someone has a more sophisticated solution.

Alex D.
  • 73
  • 9
  • See [this SO question/discussion](http://stackoverflow.com/q/23934486/258523) for why the awk range expression isn't very useful in general and how rewriting to avoid it can let you do many more useful things (like dropping a section if it matches some other criteria as you want to do here). – Etan Reisner Oct 28 '15 at 15:04
  • @EtanReisner thank you. Will take a look. In general i am not bound to using awk, any shell tools can be used. – Alex D. Oct 28 '15 at 15:21

1 Answers1

0

If you have the structured records awk can solve this problem. Given your intermediate file

2$ awk 'BEGIN{RS=ORS="!\n"} !/vrf/' interface

will print the records without "vrf"

interface TenGigE0/3/0/0
 description
 service-policy output QOS
 ipv4 mtu 1500
 ipv4 address 13.24.15.3 255.255.255.252
 carrier-delay up 3000 down 0
 load-interval 30
 dampening
!
interface TenGigE0/3/0/1
 description Link To
!
karakfa
  • 66,216
  • 7
  • 41
  • 56
  • This is magic:)) Thank you. I have spent a lot of time trying to find a solution, and it turned out to be so short:))) – Alex D. Oct 29 '15 at 08:12