I have a directory in which I have text files repesenting pages of books, named according to a convention.
Files from 0001.txt through 1239.txt are book A;
files 000.txt through 847.txt are book B;
files t000.txt through t498.txt are book C.
I want to use findstr in this directory to find a search text “two rivers” in book B only (so not in any of the files whose names contain four digits). In bash I could do this:
$ grep "two rivers" [0-9][0-9][0-9].txt
This method of pattern matching on file names doesn’t seem to work in PowerShell.
C:\Users\P\source> findstr "two rivers" [0-9][0-9][0-9].txt
FINDSTR: Cannot open [0-9][0-9][0-9].txt
The pattern you can do [0-9]{3} to specify it has to be 0-9 and exactly 3 characters versus [0-9][0-9][0-9]. The pattern above is a for files F00001.txt, F00002.txt, etc, which could be easily modified. I picked a file and put “BLUE” in the file, so my output looks like this: