Issue
I want to add a newline after number 64, using awk or sed, in ping output such as this:
64 bytes from 170.198.42.128: icmp_seq=1 ttl=60 time=83.4 ms 64 bytes from
170.198.42.128: icmp_seq=2 ttl=60 time=76.6 ms 64 bytes from 170.198.42.128: icmp_seq=3
ttl=60 time=70.8 ms 64 bytes from 170.198.42.128: icmp_seq=4 ttl=60 time=76.6 ms ---
170.198.42.128 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time
3000ms rtt min/avg/max/mdev = 70.861/76.924/83.493/4.473 ms
I've tried
cat file | sed 's/64/\n/g'
but this replaces the number 64. I want to break the pattern and display the ping command pattern starting with 64 properly.
I tried using append and insert mode ..but not using them correctly
Solution
In a substitution, &
in the replacement will be replaced with whatever matched. So:
sed 's/64/\n&/g' file
Answered By - Barmar