Awk Loop |多行

时间:2013-11-20 13:05:39

标签: unix loops awk

我需要一些帮助,循环和Awk命令。我需要过滤ping测试脚本的输出,结果是:

--- hostname1 ping statistics ---
15 packets transmitted, 14 packets received, 6% packet loss
--- hostname2 ping statistics ---
15 packets transmitted, 15 packets received, 0% packet loss
--- hostname3 ping statistics ---
15 packets transmitted, 15 packets received, 0% packet loss
--- hostname3 ping statistics ---
15 packets transmitted, 2 packets received, 86% packet loss

...而我需要的是像循环和awk过滤的东西:

第1行 - > awk'{print $(NF-3)}' - >主机名1

第2行 - > awk'{print $(NF-2)}' - >在这里我还需要%号的CUT,如果可能的话

1 个答案:

答案 0 :(得分:1)

试试这个:

[ping command here] | awk '/^---/ {printf("%s ", $2)} /%/ { print $7} {next}'