0

How can I find a string which includes quotation marks with grep? I tried a backslash to escape but this doesn't work.

For example search for the string "localStorage['api']". I tried:

grep -r "localStorage['api']" /path grep -r "localStorage[\'api\']" /path 

1 Answer 1

1

Your escaping is OK. The problem lies in the [], that grep understands as regular expressions. Thus, you need to somehow tell it to treat the string as literal. For this we have -F:

grep -F "localStorage['api']" file 

Test

$ cat a hello localStorage['api'] and blabla bye $ grep -F "localStorage['api']" a hello localStorage['api'] and blabla 

From man grep:

-F, --fixed-strings

Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.