Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Without any additional tools, using just the command line that comes with Windows 7, how can I create a batch file that will perform a file and replace of some text in a file?

share|improve this question
add comment

2 Answers

This post from Stack Overflow has the answer for Powershell: PowerShell Script to Find and Replace for all Files with a Specific Extension.

This article also explains how to search and replace text with Powershell.

share|improve this answer
add comment

Windows Powershell 2.0 comes with Windows 7, so you can use this code snippet:

$file = Get-ChildItem "C:\Path\File.ext"

ForEach-Object ($str in $file) 
{
  $content = Get-Content -Path $str
  $content | ForEach-Object {$_ -Replace "the the", "the"} | Set-Content $str
}

$file
share|improve this answer
    
    
Indeed, I should mention such things in the future. :-) –  Tom Wijsman Jul 10 '10 at 14:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.