How can I format the output of ping in bash?
Solution 1:
Use
ping -q -n -s $SIZE -c $COUNT $myHost |
awk -v host=$myhost '/packet loss/ {print host, $7}'
inside the loop.
In case you only want to print the hosts with packet loss use
ping -q -n -s $SIZE -c $COUNT $myHost |
awk -v host=$myhost '/packet loss/ {if ($7 != "0.0%") print host, $7}'
Side note: grep pattern | awk '{action}'
can usually be replaced with the much neater (and slightly faster) awk '/pattern/ {action}'