我正試圖在文件中找到確切的單詞。這個詞是在我試圖找到它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