Search code examples
windowsgitcmdgrepescaping

How to search for a string with one double quote with git grep in Windows cmd


The problem is that strings with two qoutes are searched well. But! I want to look for a string "Agent (one double quote!) inside my repo on cmd in Windows. So I having this:

git grep "\"Agent\"" > 1.txt (it works! all strings with "Agent" was found)

git grep "\"Agent" > 1.txt (error! fatal: ambiguous argument '>': unknown revision...)

Any ideas how to properly escape?


Solution

  • In Git CMD or Windows cmd console, you can use ^ to escape the " inside the terminal:

    git grep ""^""Agent" > 1.txt
    

    In Git Bash, you can simply use

    git grep '"Agent' > 1.txt
    

    See this text I made on my data with "Regex pattern:

    enter image description here