Reputation: 22448
If I run command ping google.com
. It will give continuous output on the terminal.
Example output:
64 bytes from 74.125.130.101: icmp_seq=1 ttl=42 time=980 ms
64 bytes from 74.125.130.101: icmp_seq=2 ttl=42 time=1883 ms
64 bytes from 74.125.130.101: icmp_seq=3 ttl=42 time=1947 ms
64 bytes from 74.125.130.101: icmp_seq=4 ttl=42 time=1273 ms
64 bytes from 74.125.130.101: icmp_seq=5 ttl=42 time=848 ms
64 bytes from 74.125.130.101: icmp_seq=6 ttl=42 time=1072 ms
64 bytes from 74.125.130.101: icmp_seq=7 ttl=42 time=1202 ms
Now if I want to modify each output line to show only the 64 bytes from 74.125.130.101:
part, how can I do that?
I want to know a generic method which will work with other commands too which produce real time verbose output.
Upvotes: 0
Views: 347
Reputation: 464
awk-way:
ping google.com | awk -F ":" '{print $1}'
if you need trailing colons exactly like in the question:
ping google.com | awk -F ":" '{print $1 ":"}'
grep-way:
ping google.com | grep -o "^.*:"
sed-way:
ping google.com | sed 's/\(.*:\).*/\1/'
Upvotes: 2