Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 foo.txt 中有一个 ip 地址列表,如下所示: 现在我想像这样 ping 它们: 这意味着 foo.txt 中的最后一个 ip 数字加上 100。 我怎样才能编写一个 shell 脚本来自动执行此操作. 谢谢您的回答。 192.168.0.10 192.168.0.11 192.168.0.12 ... ping -c 2 192.168.0.110 ping -c 2 192.168.0.111 ...
192.168.0.10 192.168.0.11 192.168.0.12 ...
ping -c 2 192.168.0.110 ping -c 2 192.168.0.111 ...
你可以使用 awk:
awk 'BEGIN { FS = "." }; { system("ping -c 2 " $1 "." $2 "." $3 "." $4+100) }' foo.txt
这将字符串用“.”分隔,然后使用 system 通过命令进行系统调用,并将最后一个八位字节加 100。