regex - 使用正则表达式和 sed 过滤掉 IP

标签 regex linux command-line sed

我在将正则表达式转换为 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/

相关文章:

python正则表达式匹配所有大写字母和数字或仅匹配数字

python - 在Python中使用正则表达式替换多个项目

linux - 如何从 Linux 查询 Windows 注册表项?

c++ - Linux 中的共享内存

windows - GNU sed 4.2.1 匹配第二次出现

javascript - 除了英语之外,还可以使用非英语字母字符 - React-Native

C++ 正则表达式从字符串中提取所有可能的 10 位数字

linux - Fedora 操作系统家族是什么?

linux - 使用 Linux 命令行卸载 Node.JS?

unix - zcat 无法正确解压缩文件