Terminal Ping, how to get simple integer

pingterminal

i am wondering how exactly you would get a simple integer result instead of all the miscellaneous information such as the packet size, transmission number and target.

To elaborate:
I would prefer the output to look like:

117.85

A single integer response, similar to how the syntax: ping -c 1 google.com returns a single result, however i would prefer the method to omit the detailed ping report and only displays a single number.

Thanks in advance.

Best Answer

Try this:

ping -c 1 google.com | grep "time=" | sed -E "s/(.*)time=([.0-9]+) ms/\2/"

If you want to get an minimal value for some number of requests use:

ping -q -c 5 google.com | tail -1 | cut -d "=" -f 2 | cut -d "/" -f 1

Replace 1 in -f 1 with:

  • 2 for average
  • 3 for maximum