Question

ive been using grep a lot on linux lately but now i need to use findstr to carry out the same tasks on a windows machine and cant quite get the syntax just right.

My grep command looks like:

grep "12/12/2011.\*followed by literal string" /myFile.txt

so this searches for the date and the literal string specified but can contain a mix of any other characters in between the two search terms by using .\*

Anyone know how to convert this statement to findstr? thanks

Was it helpful?

Solution

The findstr command supports the /R option to specify the search string as a regular expression. It's the default behavior, however, so you don't actually need to specify it:

findstr "12/12/2011.*followed by literal string" myFile.txt

The above should give the same results as your grep example.

OTHER TIPS

In order to match a literal string, you should use the /C flag, e.g: /C:"Your literal string here" Otherwise a space inside your regex is counted as an OR e.g. this:

findstr "12/12/2011.*followed by literal string" myFile.txt

is the same as

grep 12/12/2011.*followed|by|literal|string myFile.txt

In order to combine both, pipe the output of one into the other, like this:

findstr "12/12/2011.*" myFile.txt | findstr /C:"followed by literal text"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top