Disclaimer

These scripts come without warranty of any kind. Use them at your own risk. I assume no liability for the accuracy, correctness, completeness, or usefulness of any information provided by this site nor for any sort of damages using these scripts may cause.

Sunday, September 11, 2016

Command Equivalent to "grep" in Windows

grep in Linux/Unix, find in Windows


Many times you might have wondering what is the command available in Windows which is  equivalent for "grep" in Linux/Unix. You can use findstr command in Windows

grep
The grep command in Linux/Unix is one of the most used command.  This is used for searching patterns in text.  grep process text line by line and prints any line that matching the specified pattern. Regular Expressions can be used searching.

grep can be used in many scenarios.

Examples: Search for a file Starting with "XX" in a directory

$ ls | grep XX

List all files except file Starting with "XX" in a directory

$ ls  | grep -v XX

Search for pattern in a file and list file names and lines

$ grep 187 *

Windows - findstr

findstr command in Windows can be used for similar purpose. Now let us see how above scenarios can  be achieved using findstr command.

Examples: Search for a file Starting with "XX" in a directory

c:\ dir | findstr "XX"

List all files except file Starting with "XX" in a directory

c:\ dir | findstr /v "XX"

Search for pattern in a file and list file names and lines


c:\ findstr "Internal" *

There are more parameters that can be used in combination to get the output.