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

So much easier to remember…

  • FkYko
    10 years ago

    Or you could have written

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

    for the same thing

  • pedro
    9 years ago

    Even easier

    findstr -s “mypattern” *.cpp

  • Mike
    8 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
    8 years ago

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

  • vmsplice
    8 years ago

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

  • Eka808
    8 years ago

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