regex - 正则表达式在没有特定模式时选择特定单词?
问题描述
我有一个这种格式的数据列表:
eth0: flags=73<UP,LOOPBACK,RUNNING> mtu 1500
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0xfe<compat,link,site,host>
loop (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1: flags=73<UP,LOOPBACK,RUNNING> mtu 1500
inet6 ::1 prefixlen 128 scopeid 0xfe<compat,link,site,host>
loop (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
我需要选择eth1
(这是第一个单词,它是一个总是以 开头的单词e
)它后面没有127.0.0.1
(它也可能出现在下一行的后面)。
这里eth0
是不合格的,因为它后面是127.0.0.1
我尝试了一切,但似乎没有任何效果。甚至可以使用正则表达式吗?如果是,那怎么办?
解决方案
$ awk -v RS= -F':' '!/[[:space:]]127\.0\.0\.1[[:space:]]/{print $1}' file
eth1
这将在每个 UNIX 机器上的任何 shell 中使用任何 POSIX awk 工作。
推荐阅读
- cassandra - linux下如何配置和运行Reaper修复cassandra(centos环境)
- python - Panda DataFrame 行项目如果比较不返回正确的结果
- java - 如何使用正则表达式匹配后两个字符是倒序的前两个字符的任何字符串
- python - 如何使用以下 python bigquery api 创建表?
- mathematical-optimization - 覆盖所有矩形所需的最小矩形数?
- c# - 创建多平台 NuGet 数据包
- c# - 如何确保使用 Paramore Brighter 以“持久”传递模式发送 Rabbit MQ 消息
- r - 如何在 r 中为 .wav 文件分配插槽
- python - 循环通过 XPATH SELENIUM PYTHON
- ruby-on-rails - Chartkick 返回 t 未定义