Escape double quote in grep

前端 未结 1 854
没有蜡笔的小新
没有蜡笔的小新 2020-12-07 18:52

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

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

Tha

相关标签:
1条回答
  • 2020-12-07 19:21

    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').

    0 讨论(0)
提交回复
热议问题