2016-08-17 175 views
1

我以爲我知道這個(或至少如何谷歌爲它)!如何使用grep匹配雙引號

但我無法弄清楚在文本文件中搜索模式時如何使用grep匹配雙引號。我試圖用反斜槓來避免雙引號符號,但它似乎不起作用。

>cat trial.txt 
"Bill" is here and "Ben" is there 

> grep -iE "and \"ben\" is" trial.txt 
Unmatched ". 

我該如何得到這個工作?

+0

它適用於我的機器 – CMPS

+1

有趣的是,你的代碼適用於mingw bash 4.3.42和grep 2.2。你使用什麼版本? –

+0

見http://stackoverflow.com/questions/11995353/escape-double-quote-in-grep –

回答

1

使用單引號考慮每個字符的字面含義。

grep 'and "Ben" is' trial.txt 
+1

我是如此接近單嘗試它引用 - 但決定,而不是在我的第一個問題在stackoverflow打擾你在這裏好人。 它適用於單引號。謝謝! –