How to name the output file dynamically after a search result
abc123#sh run Building configuration... Current configuration: ! version 12.0 service timestamps debug uptime service timestamps log uptime no service password-encryption ! hostname abc123 ! ... end abc123#
というファイルの version から end までを抜き出して、abc-confg といったファイル名に書き出す方法ですが、ここでも Ed 氏の解答がスマートかな。
/^version/ { ++ok} ok { out=out sep $0; sep="\n" } $1 == "hostname" { file=$2"-config" } /^end/ { print out > file; exit}