递归文本搜索在外壳上的grep赛前whithin线 [英] Recursive text search whithin lines before the grep match in shell
问题描述
我需要帮助的路由器配置的备份数据库工作。我需要的接口的列表不具有 VRF
或关机
在它们的配置。
我得到的所有的接口配置通过配置文件列表中通过的awk'/ ^接口/,/!/
。这给了我下面的输出:
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
现在,我坚持努力排除包含 VRF
线接口。我试图做的是对grep VRF,当有一个匹配,删除包含上面的字接口的路线。不幸的是对于没有运气。也许有人有一个更复杂的解决方案。
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.
推荐答案
如果您有结构化记录的awk可以解决这个问题。鉴于你的中间文件
If you have the structured records awk can solve this problem. Given your intermediate file
2$ awk 'BEGIN{RS=ORS="!\n"} !/vrf/' interface
将打印的记录没有VRF
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
!
这篇关于递归文本搜索在外壳上的grep赛前whithin线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!