Table of Contents
Here is the way I execute grep
-like command in Windows.
Windows doesn’t have grep
command, so I used FINDSTR
command.
FINDSTR
Windows has FINDSTR
command.
Find text from file
When you search text in a file, put the file path after search keyword.
1 |
findstr word test.txt |
Find text from command output
When you search text in a output of a command, pass the output to FINDSTR
with pipe.
1 |
echo test|findstr test |
Ignore large and small character difference
Like grep
, /i
option enables us to ignore large and small character difference.
1 |
echo test|findstr /i TEST |
Show line number
You can show line number with /N
option.
1 |
echo test|findstr /n test |
Find text from files in a directory
You can search all files in a directory with *
as follows.
1 |
findstr word dirname* |
This, *
, is Windows’ normal wildcard. So you can specify extension as follows.
1 |
findstr word dirname*.txt |
Search files in a directory recursively
When you search text recursively, use /S
option.
1 |
findstr /s word dirname* |