从文本文件中提取多行

从文本文件中提取多行

来源 :

!
hostname RTR-1
!
boot-start-marker
boot-end-marker
!
logging buffered 64000 informational
no logging console
!
interface FastEthernet0/0
 description LAN
 ip address 172.16.29.250 255.255.255.0
 ip helper-address 172.18.1.130
 ip helper-address 172.18.1.127
 ip tcp adjust-mss 1350
 speed 100
 full-duplex
!
line vty 0 4
 exec-timeout 30 0
 transport input telnet ssh
 transport output telnet ssh
!
end

输出:

interface FastEthernet0/0
 ip helper-address 172.18.1.130
 ip helper-address 172.18.1.127

或者:

!
hostname RTR-1
!
boot-start-marker
boot-end-marker
!
logging buffered 64000 informational
no logging console
!
interface Vlan1
 description LAN
 ip address 172.16.29.250 255.255.255.0
 ip helper-address 172.18.1.130
 ip helper-address 172.18.1.127
 ip tcp adjust-mss 1350
 speed 100
 full-duplex
!
line vty 0 4
 exec-timeout 30 0
 transport input telnet ssh
 transport output telnet ssh
!
end

输出:

interface Vlan1
 ip helper-address 172.18.1.130
 ip helper-address 172.18.1.127

我确实想提取配置命令“helper-address”的接口名称。

上述源输出存储在文件中,或者可以直接从实时路由器中提取

答案1

grep "interface\|helper" source.file

在这里问他们任务有那么难吗?

更新:如果您的操作系统中没有,grep您可以仅用 shell-bultins 替换上面的脚本:

while read
do
  case "$REPLY" in
  *interface*) echo "$REPLY" ;;
  *helper*) echo "$REPLY" ;;
  esac
done < source.file

相关内容