![テキストファイルから複数行を抽出する[閉じる]](https://linux33.com/image/58316/%E3%83%86%E3%82%AD%E3%82%B9%E3%83%88%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%81%8B%E3%82%89%E8%A4%87%E6%95%B0%E8%A1%8C%E3%82%92%E6%8A%BD%E5%87%BA%E3%81%99%E3%82%8B%5B%E9%96%89%E3%81%98%E3%82%8B%5D.png)
源泉:
!
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
仕事がとても難しいかどうかここで尋ねてください。
アップデート:OSに存在しない場合は、grep
上記のスクリプトをshell-bultinsに置き換えることができます。
while read
do
case "$REPLY" in
*interface*) echo "$REPLY" ;;
*helper*) echo "$REPLY" ;;
esac
done < source.file