digの結果から ANSWER SECTION のみ抜き出す
dig の出力結果は以下のような感じです。
$ dig google.com ; <<>> DiG 9.5.0-P2 <<>> google.com ;; global options: printcmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 17158 ;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;google.com. IN A ;; ANSWER SECTION: google.com. 136 IN A 72.14.205.100 google.com. 136 IN A 74.125.45.100 google.com. 136 IN A 209.85.171.100 ;; Query time: 301 msec ;; SERVER: 60.254.193.158#53(60.254.193.158) ;; WHEN: Wed Jan 7 23:10:48 2009 ;; MSG SIZE rcvd: 76
pshで、このdigの結果から ANSWER SECTION のみ抜き出します
$ dig google.com | {print if/ANSWER SECTION/../^$/}q ;; ANSWER SECTION: google.com. 36 IN A 72.14.205.100 google.com. 36 IN A 74.125.45.100 google.com. 36 IN A 209.85.171.100