为什么ping -c 1 google.com | grep "bytes from" | cut -d = -f 1
会返回64 bytes from 216.58.216.206: icmp_seq
而不是0 ttl
?我希望-f 1
返回0 ttl
。
答案 0 :(得分:3)
您可以使用awk
完成所有操作并避免grep
,cut
:
ping -c 1 google.com | awk -F= '/bytes from/{print $2}'
0 ttl
btw你的命令应该是:
ping -c 1 google.com | grep "bytes from" | cut -d = -f 2
获得与0 ttl
相同的输出是字段#2
答案 1 :(得分:1)
ping -c 1 google.com | grep "bytes from" | cut -d = -f2
0 ttl
如果你希望到0 ttl那么
ping -c 1 google.com | grep "bytes from" | cut -d = -f1-2
64 bytes from yyz08s14-in-f14.1e100.net (172.217.2.142): icmp_seq=0 ttl