Ubuntu openstack中子命令,精确字符串的grep

Ubuntu openstack中子命令,精确字符串的grep,ubuntu,grep,Ubuntu,Grep,我需要在下面的输出中精确匹配“router_dallas”。我对字符串路由器不感兴趣 NetworkNode001:~$ neutron router-list | grep dallas | awk '{print $4}' router_dallas1 router_dallas 我试着使用“中子路由器列表| grep dallas | awk'$1==”dallas“{print$4}”,但它不起作用。有人能告诉我是否有更好的方法来过滤这个输出吗 grep '\brouter_dall

我需要在下面的输出中精确匹配“router_dallas”。我对字符串路由器不感兴趣

NetworkNode001:~$ neutron router-list | grep dallas | awk '{print $4}'
router_dallas1
router_dallas
我试着使用“中子路由器列表| grep dallas | awk'$1==”dallas“{print$4}”,但它不起作用。有人能告诉我是否有更好的方法来过滤这个输出吗

grep  '\brouter_dallas\b' input 
`\b` is to put word boundaries. 


您可以使用
$
匹配字符串的结尾,并使用
^
匹配开头(假设行中只有您的内容):


grep“^router_dallas$”

你能发布
中子路由器列表的完整输出吗?
网络节点001:~$neutront router list | grep dallas | 610503e6-c45e-4d6d-a4f8-e301cb7830d4 | router_dallas1 | |网络id:“704e5640-a581-4f6f-b212-9E5EDD37C3A”,“ENABU snat”:真,“外部固定子网id:”“e55c36d5-2ebe-436b-93e0-b6077f360c5e”,“ip地址”:“10.116.240.164”}]| False | False | ac5f9918-ed2f-4070-a5dc-ef58d9ba5ab8 |路由器|达拉斯| null | False | False |这是完美的。它成功了,但不确定是否会成功如果字符串包含-不确定,为什么不让我投票:(我怎么投票,它不让我这么做!-w在以下方面不起作用:内联`root@myHost:/home/root#openstack volume show vol1 | grep-w'status'| os vol mig status attr:migstat | None | status | in use`您需要使用
-E
以提供多个输入作为搜索模式。
openstackvolume show vol1 | grep-Ew“status | os vol mig status attr:migstat | None | status | in use”
不幸的是,这并不仅仅是内容,还包含许多其他字符。但是,这是一个好信息!
grep -w 'router_dallas' input 


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