Windows: Grep Equivalent – CMD & PowerShell

The grep command in Linux is widely used for parsing files and searching for useful data in the outputs of different commands.

The findstr command is a Windows grep equivalent in a Windows command-line prompt (CMD).

In a Windows PowerShell the alternative for grep is the Select-String command.

Below you will find some examples of how to “grep” in Windows using these alternatives.

Grep Command in Windows

Grep the output of a netstat command for a specific port:

# Windows CMD
C:\> netstat -na | findstr "PORT"

# Windows PowerShell
PS C:\> netstat -na | Select-String "PORT"

Grep a file for a pattern that matches a regular expression (case insensitive):

# Windows CMD
C:\> findstr /i "^SEARCH.*STRING$" file.txt

# Windows PowerShell
PS C:\> Select-String "^SEARCH.*STRING$" file.txt

Display help for the Windows grep command equivalents:

# Windows CMD
C:\> findstr /h

# Windows PowerShell
PS C:\> get-help Select-String