grep如何精确匹配

grep不加选项时不是精确匹配,例如:

[[email protected] ~]

# ifconfig eth0
eth0: flags=4163 mtu 1500
inet 192.168.1.112 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::5054:ff:fe82:bc7a prefixlen 64 scopeid 0x20
ether 52:54:00:82:bc:7a txqueuelen 1000 (Ethernet)
RX packets 4219 bytes 317709 (310.2 KiB)
RX errors 0 dropped 9 overruns 0 frame 0
TX packets 1486 bytes 199942 (195.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

[[email protected] ~]

# ifconfig eth0 | grep inet
inet 192.168.1.112 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::5054:ff:fe82:bc7a prefixlen 64 scopeid 0x20

怎么精确匹配只有 inet的行呢,很简单,加-w

[[email protected] ~]

# ifconfig eth0 | grep -w inet
inet 192.168.1.112 netmask 255.255.255.0 broadcast 192.168.1.255
此条目发表在grep分类目录,贴了标签。将固定链接加入收藏夹。

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注