Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Delete Line Containing Specific Word and Next 2 Lines

$
0
0

I am attempting to write a powershell script that will delete the line containing the <PROCEDURE> in multiple text files and delete the next 2 lines after <PROCEDURE>. No matter what I try, I can only manage to delete the line containing <PROCEDURE> and not the next 2 lines.

$start = "C:\test\"
Get-ChildItem -Recurse $start -Filter "*.txt" | Foreach{
 $Path = $_.FullName
 $content = Get-Content $Path | Where-Object {$_ -notmatch "<PROCEDURE>"}

 $content | Set-Content $Path -Force
}


Viewing all articles
Browse latest Browse all 6937

Trending Articles