-1

What changes need to be made to the following findstr command in order to return a list of all the uses of the exact phrase "port" : " in all the files contained in the directory and subdirectories?

findstr /I "port" : " *  

Obviously, escaping the quotes is necessary, but what specific syntax is required to escape the quotes while still getting the expression to return the expected values?

This is on windows 8.1 using cmd.exe.

Harry Johnston
  • 35,639
  • 6
  • 68
  • 158
CodeMed
  • 9,527
  • 70
  • 212
  • 364

1 Answers1

2

you need to escape the double quote, and since your regular expression uses spaces, use the /c switch to pass a search string instead of space separated regexes:

findstr /I /c:"port\" : " *

from here:

multiple Regular Expressions can be separated with spaces, just the same as separating multiple words (assuming you have not specified a literal search with /C) but this might not be useful if the regex itself contains spaces.

Scott Weaver
  • 7,192
  • 2
  • 31
  • 43
  • This is a single quote: `'`. You're actually talking about a double quote. – Laurel May 16 '16 at 21:44
  • This does not work. The results of your suggestion produces every instance of `"could_be-any_string" : "`. In fact, I had already tried your suggestion before I posted this OP. If someone wishes to answer this question, please test it in a directory on your machine containing files with the specified string to match. Thank you. – CodeMed May 16 '16 at 22:38
  • updated. /c switch seems to get the desired behavior. – Scott Weaver May 16 '16 at 22:59
  • 3
    I think the opening and closing quotes are supposed to be part of the search string, so you probably want `/c:"\"port\" : \""` – Harry Johnston May 16 '16 at 23:44