There are many articles that explain how to show n lines after or before a grep match in shell.
I need a little more complicated solution: grep for a word and when it is matched I need to further grep within the next n lines. Ideally, as a result i need all the lines that matched the first search and DID NOT match the grep within the next n lines. Some sort of text search recursion.
This is not bound to grep though, any Linux/Unix tool can be used.
Sample output:
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
I only need a list of interfaces that do not have vrf line in their config. Note that i get this output from backup database, not the router itself.
One of my clumsy ideas was to merge all the text between the word "interface" and the ! into one line and to filter out the lines that contain the word "vrf". I used awk '/^interface/,/!/' but failed to merge the output into one line.