5

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. 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?

Shamanth Huddar
  • 53
  • 1
  • 1
  • 4

1 Answers1

12

Use single quotes to consider literal meaning of every character.

grep 'and "Ben" is' trial.txt
P....
  • 17,421
  • 2
  • 32
  • 52
  • 3
    I was this close to trying it with single quotes - but decided instead to bother you nice folks over here at stackoverflow with my first question. It works perfectly with single quotes. Thanks! – Shamanth Huddar Aug 18 '16 at 04:52