PowerShell replace text in files

In the example I am replacing every .html file in the folder that has my line of
the words ‘old Text’ and replacing with words ‘new TeXT’ *(using Power Shell to replace strings)

You can change the file extension and update the location path to a single file to replace text in one file only.

 get-childItem 'C:\scripts\*.txt' -recurse | ForEach {
(Get-Content $_ | ForEach {$_ -replace 'OLD TeXT', ' NEW TeXT'}) | 
Set-Content $_ 
}

share with friends

Share to Google Buzz
Share to Google Plus
Share to LiveJournal
Share to Odnoklassniki
No comments yet.

Leave a Reply