grep for Windows
Today I wanted to consolidate tags and categories on this blog. Every post is just a plain text file, so on unix the tool I'd reach for is grep. Select-String is a good choice for this task in PowerShell.
- Get all articles
- Show only the line with the word "Category" on it
Just like in unix, the pipe operator makes it easy to compose functionality.
1Get-ChildItem -File -Path ".\content" | Select-String "Category"
Full cmdlet names are great for scripts, but in the shell it's usually a little faster to just go with the aliases.
1ls -File -Path ".\content" | sls "Category"
Finally, sometimes it's really important to only match the correct case.
1ls -File -Path ".\content" | sls "Category" -CaseSensitive
As always, for more:
1Get-Help Select-String -Examples