0

I would like to as if it is possible to strip the result of the 'ping' command form the last three lines which are always:

--- domain.com ping statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 3.837/4.501/4.839/0.469 ms 

Would it be possible to make ping to NOT show this lines?

I have tried with the following:

ping -c2 domain.com | xargs grep -v "statistics \|transmitted\|round-trip"

and also:

ping -c2 domain.com | grep -v "statistics \|transmitted\|round-trip"

But it does not seem to be working. This is tested on a Mac only. It is not tested on Linux.

So, i was wondering if it will be possible to make this work somehow? May be with awk or something?

  • Do you want to get rid of the newline aswell? – Panki May 29 at 9:52
  • @Panki the new line is not an issue. The last three lines are my concern. – Miro May 29 at 10:41
0
ping -c2 domain.com | head -n-3

To get rid of the leading newline aswell:

ping -c2 domain.com | head -n-4
  • Thank you. This worked perfectly :) and it was exactly what I was looking for. – Miro May 29 at 10:45
0

How about that?

ping -c 2 domain.com | grep -E "PING|icmp_seq"

Or if You don't want first line

ping -c 2 domain.com | grep -E "icmp_seq"

Or If You really want to delete lines

ping -c 2 domain.com | sed '/statistics\|packets\|rtt\|^$/d'

^$ - is to delete empty lines

  • Thanks. This worked fine as well. – Miro May 29 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.