bash - 在匹配另一行之后删除匹配的行
问题描述
我想得到你的帮助:
我有一个数千行的文件,我需要找到文件的一部分并在适当的位置删除一些行:
这是部分,我要删除的行已标记:
interface Vlan824
description WRES_824
vrf forwarding V211
ip address 172.17.224.2 255.255.240.0 #### Delete this ####
ip helper-address xxxx
ip helper-address xxxy
no ip redirects
no ip proxy-arp
ip verify unicast source reachable-via rx 2699
standby delay minimum 0 reload 60
standby version 2
standby 0 ip 172.17.224.1 #### Delete this ####
standby 0 priority 110
standby 0 preempt delay minimum 300 reload 300
shutdown
standby 1 ipv6 FE80::1 #### Delete this ####
standby 1 ipv6 <IPV6-PREFIX-1>0E:824::1/64 #### Delete this ####
standby 1 priority 110
standby 1 preempt delay minimum 300 reload 300
ipv6 address FE80::2 link-local #### Delete this ####
ipv6 address <IPV6-PREFIX-1>0E:824::2/64 #### Delete this ####
ipv6 nd prefix <IPV6-PREFIX-1>0E:824::/64 no-advertise #### Delete this ####
ipv6 nd managed-config-flag
ipv6 nd other-config-flag
no ipv6 redirects
ipv6 dhcp relay destination xxx
ipv6 dhcp relay destination xxx
ipv6 verify unicast source reachable-via rx URPF
bfd interval 750 min_rx 750 multiplier 3
arp timeout 300
!
此 sed 将删除上述行(第三行除外),但我只需要在该部分中执行此操作。
sed -i '/224.1/d; /224.2/d; /224.3/d; /:224::/d; /:824::/d' FILE.txt
我会很感激你的帮助。
费尔
编辑:
为了澄清我需要什么,如果我有这个文件:
aaa
bbb
hhh
eeb
ccc
!
aab I need to find this section ( from aab to ggc )
hhb and delete just the eeb line
eeb
ffb
ggc
!
aac
hhc
eeb
ffc
解决方案
假设您要编辑的部分是 Vlan824 部分(以 ! 字符结尾),匹配删除行的模式是 224.1 和 FE80
sed -n '/Vlan824/,//p;/^\!/q' your-file | grep -v '224.1\|FE80'
推荐阅读
- ansible - 使用 Ansible 从包含特定文件名的文件中复制某些文件
- c++ - 奇怪的编译错误:编译器错误还是我自己的?
- wpf - WPF - 单击外部时未关闭弹出窗口
- javascript - 如何在不使用 eval() 的情况下使用回调更新函数包装中的条件?
- sql - 如何在 sql 过程中管理并发访问
- firebase - 如何知道 Firebase Spark 计划限制是针对每个项目还是针对整个项目?
- php - Yii2 一个下拉列表中的两个 onchange 事件
- angular - Angular 将 img[src] 设置为 null 甚至认为它具有价值
- javascript - 在运行功能时禁用按钮
- c# - 如何将 MongoDB 日期时间转换为 C# 日期时间?