【发布时间】:2018-10-19 03:28:41
【问题描述】:
我有一个包含以下内容的文件:
/interface bridge
add comment="Bridge VLAN18" fast-forward=no mtu=1500 name=\
bridge-vlan18 protocol-mode=none
/interface ethernet
set [ find default-name=ether3 ] comment="Ether3" \
name=cobre
set [ find default-name=ether5 ] comment="Ether5" disabled=\
yes name=cobre2
/interface bridge port
add bridge=bridge-vlan18 interface=vlan18.bonding-ptp3
add bridge=bridge-vlan18 interface=vlan18.ether13
add bridge=bridge-vlan18 interface=vlan18.eoip-funes-vlan18
add bridge=bridge-vlan18 comment="VLAN18" \
interface=eoip-orono-vlan18 path-cost=20
add bridge=bridge-vlan18 interface=vlan18.bonding-ptp5
/ip firewall connection tracking
set tcp-established-timeout=10m
我需要提取从“/”到下一个“/”的每一个文本块,没有第二个斜线行。我尝试了以下(提取“接口桥”块):
sed -n "/^\/interface\ bridge\s$/,/^\//p" file.txt
但我明白了:
/interface bridge
add comment="Bridge VLAN18" fast-forward=no mtu=1500 name=\
bridge-vlan18 protocol-mode=none
/interface ethernet
我需要得到:
/interface bridge
add comment="Bridge VLAN18" fast-forward=no mtu=1500 name=\
bridge-vlan18 protocol-mode=none
需要使用原生 linux 工具(grep、sed、awk 等)。有什么建议我该怎么做?
【问题讨论】: