我有如下一個sample.txt的文件:正則表達式找到一個詞
1.hi _plane_ is
2.hi airplane is
3.hi plane is
4.hi _plane- is
5.hi :plane: is
plane
there is a plane here
我想找到一個詞「平面」不是內部的其他詞,說「飛機」, 這樣的grep後,輸出將只是如下面(僅第2行,將過濾掉)
1.hi _plane_ is
3.hi plane is
4.hi _plane- is
5.hi :plane: is
plane
there is a plane here
我嘗試:
grep -w "plane" sample.txt
grep "\bplane\b\|\Bplane\B" sample.txt
卜輸出與我所期望的不相符。 實際上我應該如何使用grep來獲得正確的結果?
非常感謝。
這完全是我想要的,非常感謝 – CSJ