How to “grep -v” in PowerShell

This is more for my own reference in the future when I forget the command.

If you are used to Linux / Unix and use “grep -v” to filter out lines in text files (-v does the opposite to grep without -v) then the following command will be useful for PowerShell in Windows.

gc sourcefile.txt | ?{$_ -notmatch 'HashedSaltedPassword'}

The above would take sourcefile.txt and display all the lines except the lines containing “HashedSaltedPassoword”. You can then “> outfile.txt” on the end to dump all that data to a new file instead of to the screen.

gc sourcefile.txt | ?{$_ -notmatch 'HashedSaltedPassword'} > outfile.txt
This entry was posted in Uncategorized. Bookmark the permalink.

Comment on this topic

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s