Trying to capture only the packets return time from ping output, I issued
$ ping 192.168.0.1 | grep -o '[^ =]* ms'
and it worked, displaying each packet time when it arrived. Since I also wanted to get rid of the unit of time, thought this would suffice:
$ ping 192.168.0.1 | grep -o '[^ =]* ms' | grep -o '^[^ ]*'
But, to my surprise, it hangs, showing no output. Replacing the first command with an echo of a sample line from ping output, however, works as expected (it outputs 5.07):
$ echo '64 bytes from 192.168.0.1: icmp_seq=10 ttl=64 time=5.07 ms' | grep -o '[^ =]* ms' | grep -o '^[^ ]*'
I found other means of getting only the time without the milissecond unit, but still: What is the issue with ping command? Why is passing it through one pipe is OK, but not through two?
PS: These below also fail, while their echo versions succeed, thus the problem can't be with grep
$ ping 192.168.0.1 | grep -o '[^ =]* ms' | sed 's_ ms__'
$ ping 192.168.0.1 | grep -o '[^ =]* ms' | cut -f 1 -d ' '
$ ping 192.168.0.1 | cut -f 7 -d ' ' | cut -f 2 -d '='
grepis filled), not "hanging". If you use GNUgrep, use it with--line-buffered. This may well be a dupe of piped command after grep not working – Kusalananda Feb 12 '20 at 22:06