Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

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

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.