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:

Linux/Unix/macOS
# 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

Meta-character:
.	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: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/findstr

-


Have Questions? Post them here!

Topics Coverage:


🎉 We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.

Follow Us: GitHub | Facebook | Twitter | Instagram