我在将正则表达式转换为 Centos 5.5 上可用的 sed 命令时遇到了真正的麻烦。
我想从字符串中过滤出 IP 地址:
"example.org has address 123.45.67.890" -> "123.45.67.890"
到目前为止我的正则表达式是:
/([a-zA-Z\. ]+)([0-9\.]+)/
我使用 sed 命令的一个例子是:
host example.org | grep 'has address' | sed 's/\([a-zA-Z\\. ]+\)\([0-9\\.]+\)/\2/'
但我从该命令中得到的只是对 sed 的输入:“example.org 的地址为 123.45.67.890”
有什么想法吗?
最佳答案
host example.org | awk '/has address/ {print $4 }'
关于regex - 使用正则表达式和 sed 过滤掉 IP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5107540/