How to avoid double quote with GNU grep for windows / dos?

I'm trying to find

Build = "Foobar

in all files and direct the output to tmp.txt

I tried (cmd / error)

grep -r "Assembly = \" Foobar ". β†’ tmp.txt error (invalid argument)

grep -r "Assembly =" "Foobar". β†’ tmp.txt
error (not enough space)

grep -r 'Assembly = "Foobar". β†’ tmp.txt
error (not enough space)

very upset. Any suggestions?

+6
source share
1 answer

You need to worry about escaping quotes for both grep and cmd.exe

grep expects quotes to be escaped as \"

cmd.exe marks quotation marks as ^" . Quotation is a finite state machine meaning non-exclusive quotation marks to enable or disable quotation semantics. When quoting is turned on, special characters such as < , | , & etc., are treated as literals. first vague citation includes semantics quotes. The following quote disables semantics citations. Turn a quote can only be switched off when quoting. Unbalanced quotes lead to citation residue. Thus, in your case >>tmp.txt is not regarded as a redirection cmd.exe, so it is passed to grep as an argument.

Any of the following actions will be performed:

 grep -r "Assembly=\"Foobar^" . >>tmp.txt grep -r ^"Assembly=\"Foobar" . >>tmp.txt grep -r ^"Assembly=\^"Foobar^" . >>tmp.txt grep -r Assembly=\^"Foobar . >>tmp.txt 

If your search query included spaces, then grep needs the enclosed quotation marks, therefore you will need any of the first three forms. The last form will not work with spaces in the search expression.

+9
source

Source: https://habr.com/ru/post/957515/


All Articles