Deleting entire lines in a text file based on a partial string match with Windows PowerShell
Solution 1:
Here's what I would do:
Get-Content .\in.txt | Where-Object {$_ -notmatch 'not'} | Set-Content out.txt
Snark's line does the same, but it starts with loading all of the file into an array, which may be problematic with big files memory-wise.
Solution 2:
This will work:
(Get-Content "D:\Logs\co2.txt") -notmatch "not" | Out-File "D:\Logs\co2.txt"