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:

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail:

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap