How to modify output of ping command in terminal using shell? -
the output of typical ping command -
--- 192.168.1.107 ping statistics --- 2 packets transmitted, 1 received, 50% packet loss, time 1008ms rtt min/avg/max/mdev = 0.288/0.288/0.288/0.000 ms
i want display "50% packet loss" portion on terminal window when run ping command in shell script. how should proceed ?
using grep
-o
tells grep
print matching portion:
ping -c2 -q targethost | grep -o '[^ ]\+% packet loss'
using awk
if output of ping viewed comma-separated fields, then, shown in sample output, packet loss info in third field. allows use awk follows:
ping -c2 -q targethost | awk -f, '/packet loss/{print $3;}'
Comments
Post a Comment