Grep in Powershell
Every now and then I need to grep in Windows (grep is a powerfull Unix tool, which enables you to search for strings mathing regular expressions in files.) This week I needed to search for strings in resx files. On Linux/Unix, I would
grep -r "pattern" dir
, which will search recursively in the directory dir for files containing the pattern pattern.
There exists a number of ways to do this on Windows
or use the findstr DOS command
And then there is my new old friend Powershell. I first learned about Powershell in 2009 when I started to work professionally on Windows. And I fell instantly in love with it.
The Powershell equivalent of the above Unix command is Get-ChildItem -recurse | Select-String -pattern "pattern" | select name
Adding a grouping operator for nice formatting makes it like this:
Get-ChildItem -recurse | Select-String -pattern "pattern" | group path | select name
On the screenshot above, I recursively searched for the string "Linux" in the drivers folder in Windows.