openstack neutron command, grep for exact string



我需要在下面的输出中完全匹配"router_dallas"。我对字符串router_dallas1不感兴趣。

NetworkNode001:~$ neutron router-list | grep dallas | awk '{print $4}'
router_dallas1
router_dallas

我尝试使用"中子路由器列表|格瑞普达拉斯 |awk '$1 == "达拉斯" { 打印 $4 }'",但它不起作用。有人可以让我知道是否有更好的方法来过滤此输出吗?

grep  'brouter_dallasb' input 
`b` is to put word boundaries. 

grep -w 'router_dallas' input 

from grep help -w, --word-regexp         force PATTERN to match only whole words

您可以使用$来匹配字符串的结尾,并使用^来匹配开头(假设您的东西是该行上唯一的东西(:

grep "^router_dallas$"

最新更新