Kos*_*hur 22 grep ip shell-script
我有一个生成一些输出的脚本。我想检查任何 IP 地址的输出,例如
159.143.23.12
134.12.178.131
124.143.12.132
if (IPs are found in <file>)
then // bunch of actions //
else // bunch of actions //
Run Code Online (Sandbox Code Playgroud)
是fgrep
个好主意吗?
我有 bash 可用。
Ija*_*han 43
是的,您有很多选项/工具可供使用。我刚试过这个,它有效:
ifconfig | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b"
因此您可以使用grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b"
grep 输出中的 IP 地址。