I wanted to do grep for keywords with double quotes inside. To give a simple example:

echo "member":"time" | grep -e "member\"" 

That does not match. How can I fix it?

1 Answer

The problem is that you aren't correctly escaping the input string, try:

echo "\"member\":\"time\"" | grep -e "member\"" 

Alternatively, you can use unescaped double quotes within single quotes:

echo '"member":"time"' | grep -e 'member"' 

It's a matter of preference which you find clearer, although the second approach prevents you from nesting your command within another set of single quotes (e.g. ssh 'cmd').

5

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy