我正试图在文件中找到确切的单词。这个词是在我试图找到它myServer上,文件内容为:Bash Grep确切搜索
This is myServer and it is cool
This is myServer-test and it is cool
我这里还有我的各种尝试的结果,要做到这一点:
grep '^myServer$' test-file.txt
grep -Fx myServer test-file.txt
--> no results
grep -w myServer test-file.txt
grep -w myServer test-file.txt
grep '\<myServer\>' test-file.txt
grep '\bmyServer\b' test-file.txt
-->
This is myServer and it is cool
This is myServer-test and it is cool
我失去了一些开关这里?
很多谢谢。
对不起,但仍返回两条线 – Sunshine 2013-04-04 16:38:36
是的,它会因为连字符也被认为是一个字边界。 – anubhava 2013-04-04 16:39:02
@阳光:请检查我编辑的答案。 – anubhava 2013-04-04 16:45:51