Emulating Grep in Powershell

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 *.cs -recurse | select-string -pattern "mypattern" -caseSensitive

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

  • FkYko
    5 years ago

    Or you could have written

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

    for the same thing

  • pedro
    4 years ago

    Even easier

    findstr -s “mypattern” *.cpp

  • Mike
    3 years ago

    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

  • vmsplice
    3 years ago

    Thank you so much for sharing. Most accurate comparing against “grep”

  • vmsplice
    3 years ago

    Am referring to Mike with the example on findstr. ^_^

  • Eka808
    3 years ago

    Finally a grep on windows !!!!!! thank’s for sharing