我想在ping输出中使用awk或sed在数字64之后添加换行符:
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
我试过了cat file | sed 's/64/\n/g'
但这代替了数字64。我想破坏模式并正确显示以64开头的ping命令模式。我尝试使用添加和插入模式..但未正确使用它们
最佳答案
在替换中,替换中的&
将替换为匹配的内容。所以:
sed 's/64/\n&/g' file
关于bash - 找到匹配项后如何添加换行符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24707352/