-2

私の要件は、F-5 構成を調べることです。

何かのようなもの:

 If x=virtual
 grep for virtual | pool | destination

ファイルは次のようになります。

virtual vs_website_443 {
snat automap
pool pl_website_443
destination 11.11.11.11:https
ip protocol tcp
persist pr_cookie_JSESSION_AP
profiles {
   oneconnect-ebiz-blah {}
  pr_http_ebiz_x_forwarded_for {}
   serverssl {
      serverside
  }
   tcp-lan-optimized {}
   wildcard.origin.website.com {
      clientside
   }
}
4

1 に答える 1

0

plainbashですが、POSIX sh に簡単に変換できます。

#!/usr/bin/env bash

in=0 # whether we are inside a 'virtual' block
     # such a block ends once we meet a line that starts with '}'

while read -r
do
    if [[ $REPLY =~ ^virtual ]]; then
        in=1
        echo "${REPLY% *}"
    elif (( in )); then
        if [[ $REPLY =~ ^pool ]]
        then echo "$REPLY"
        elif [[ $REPLY =~ ^destination ]]
        then echo "${REPLY%:*}" # or just "$REPLY" if you want the ':https' part
        elif [[ $REPLY =~ ^} ]]
        then in=0
        fi
    fi
done < file

あなたのデータはどこにfileありますか。これを変更して"$1" 、ファイルをスクリプトの引数として指定できます。

与えられたデータでテストされ、以下を返します:

virtual vs_website_443
pool pl_website_443
destination 11.11.11.11

プレーンを使用してawk

awk '$1 == "virtual" { f=1; print $1,$2; next }         \
     f == 1 { if ($1 == "pool") { print }               \
              else if ($1 == "destination") { print }   \
              else if ($0 ~ /^}/) { f=0 }               \
     }' file

指定されたデータ出力は次のとおりです。

 $ awk '$1 == "virtual" { f=1; print $1,$2; next } f == 1 { if ($1 == "pool") { print } else if ($1 == "destination") { print } else if ($0 ~ /^}/) { f=0 } }' file
virtual vs_website_443
pool pl_website_443
destination 11.11.11.11:https
于 2012-10-15T19:56:30.577 に答える