简体   繁体   English

如何使用grep匹配双引号

[英]How to match double quotes using grep

I thought I knew this(or at least how to google for it)!我以为我知道这一点(或者至少如何在谷歌上搜索它)!

But I can't figure out how to match double quotes using grep when searching for patterns in text file.但是在文本文件中搜索模式时,我无法弄清楚如何使用 grep 匹配双引号。 I tried to escape the double quotes symbol with a backslash, but it doesn't seem to work.我试图用反斜杠转义双引号符号,但它似乎不起作用。

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

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

How do I get this to work?我如何让这个工作?

使用单引号来考虑每个字符的字面含义。

grep 'and "Ben" is' trial.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM