Avoid double quotes in grep

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

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

This is not appropriate. How to fix it?

+46
linux shell
Aug 16 '12 at 21:00
source share
1 answer

The problem is that you are not correctly avoiding the input string, try:

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

Alternatively, you can use double quotes without quotes in single quotes:

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

This is a preference question, which you will find more clear, although the second approach does not allow you to embed your command in another set of single quotes (for example, ssh 'cmd' ).

+75
Aug 16 2018-12-21T00:
source share



All Articles