我需要帮助制作一个ping图,基本上看起来像linux上的一个,我如何得到ping输出?
ping -c 1 -i 1 "google.com"
我想要这样的输出
86 ms
86 ms
97 ms
36 ms
我尝试使用字符串分割器
你可以这样做:
ping -i 1 "google.com" | awk -F '=' '/time=/ {print $NF}'
输出如下
PING google.com (142.250.74.46) 56(84) bytes of data.
64 bytes from arn09s22-in-f14.1e100.net (142.250.74.46): icmp_seq=1 ttl=113 time=12.9 ms
64 bytes from arn09s22-in-f14.1e100.net (142.250.74.46): icmp_seq=2 ttl=113 time=10.7 ms
64 bytes from arn09s22-in-f14.1e100.net (142.250.74.46): icmp_seq=3 ttl=113 time=10.7 ms
64 bytes from arn09s22-in-f14.1e100.net (142.250.74.46): icmp_seq=4 ttl=113 time=11.9 ms
...
到
12.9 ms
10.7 ms
10.7 ms
11.9 ms
...
使用sed
命令的相同操作将是:
ping -i 1 "google.com" | sed -n 's/.*time=//p'