While How to Terminate Script after a certain number of output is very similar to what I'm looking for, I noticed that this does not work if I am grepping the output.
For example, this works:
➜ ~ ping google.com | head -n 5
PING google.com (142.251.32.206): 56 data bytes
64 bytes from 142.251.32.206: icmp_seq=0 ttl=115 time=30.867 ms
64 bytes from 142.251.32.206: icmp_seq=1 ttl=115 time=32.049 ms
64 bytes from 142.251.32.206: icmp_seq=2 ttl=115 time=37.133 ms
64 bytes from 142.251.32.206: icmp_seq=3 ttl=115 time=31.965 ms
➜ ~
but what if I want to grep for only lines containing bytes from? This doesn't work (noo output at all):
➜ ~ ping google.com | grep -i "bytes from" | head -n 5