Emulating Grep in Powershell

by Marshall on December 6, 2007

Grep is one of my favorite tools to help me find something in a set of files. Since I cannot download Cygwin at work, I have to make due with what I have.

The following is a translation of grep -R "mypattern" *.cpp for Powershell.

gci C:\path\to\files\* --include *.cpp -recurse | select-string -pattern "mypattern" -caseSensitive

<sarcasm>
So much easier to remember…
</sarcasm>

3 comments

Or you could have written

ls * *.cpp -r | ss mypattern -ca

for the same thing

by FkYko on March 25, 2010 at 1:00 am. #

Even easier

findstr -s “mypattern” *.cpp

by pedro on September 9, 2010 at 12:05 pm. #

For basics….
$ new-alias grep findstr
$ dir | grep -i tesT
-a— 10/10/2011 11:55 AM 1761 test-port.ps1
-a— 10/11/2011 10:15 AM 3133 test-ports.ps1
-a— 10/13/2011 3:00 PM 496 test_slurp.ps1

by Mike on October 13, 2011 at 5:37 pm. #

Leave your comment

Required.

Required. Not published.

If you have one.