200 packets transmitted, 200 received, +199 duplicates, 0% packet loss, time 199258ms


比如我有个ping数据,我想取这一行我可以ping完后,结果存到一个文件,然后grep这个文件获取如上信息


grep ‘200 packets transmitted’ 文件

然后我想获取到其中的丢包率,即0%可用-o的参数进行如下:


echo “200 packets transmitted, 200 received, +199 duplicates, 0% packet loss, time 199258ms”|grep -oE '[0-9]%'