Grep Alternative for Windows CMD or PowerShell: findstr

Grep alternative for Windows CMD or Powershell

grep is the most used and powerful command line tool available for Unix and Linux Distributions, if you are a Windows Operating System and wondering if there is a similar or alternative to grep for Command Line - CMD or PowerShell, well findstr is the command you should look at.

Example: grep vs findstr:

# ls| grep sample.txt
Windows: CMD/PowerShell
C:\> dir | findstr sample.txt

Some Findstr Examples

To find the word Michael in songs.txt file.

> findstr Micheal songs.txt

To find the word Easter or Christmas in songs.txt file.

> findstr Easter Christmas songs.txt

To find the String Micheal Jackson in songs.txt file.

> findstr "Micheal Jackson" songs.txt

Case insensitive search /i

> findstr /i "Micheal Jackson" songs.txt

.	Wildcard - Any character
*	Repeat - Zero or more occurrences of the previous character.
^	Beginning line position - Beginning of the line.
$	End of the line.
[x-y]	Range - Any characters within the specified range.
\x	Escape - Literal use of a meta-character.
\	Ending word position

Read More:


Have Questions? Post them here!

Top Hashtags: