As we know we need to get the value of time from "ttl=251 time=1.79" we can just split by the "=" character with awk:
line="ttl=251 time=1.79"
echo "${line}" | awk '{split($0,a,"="); print a[3]}' | tr -d '\n'
tr -d to grab the numerical value without \n
NOTE: This is just for the command line. In the script, you don't need the "tr -d"
In a ping command where the output is like this:
ivo@spain-nuc-03:~/Downloads/TestStackoverflow$ ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=3.35 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=2.50 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=2.64 ms
We could get a list with the time:
ivo@spain-nuc-03:~/Downloads/TestStackoverflow$ ping 192.168.1.1 | awk '{split($0,a,"="); print a[4]}'
2.47 ms
6.20 ms
4.85 ms
2.52 ms
1.01 ms
2.58 ms
Just remember to change the position to 4 in awk.
Hope this helps!