PowerShell: Extracting certain lines in any file

I had quite a large file that I needed to parse, and the challenge was to extract certain lines that didn’t match a certain condition.  The solution . . . PowerShell, like so:

select-string -path filename -notmatch "criteria" | foreach {$_.line} | out-file -filepath filename -encoding ascii

That’s it!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.