Q: command line find/replace help I've got a set of 5000+ files that I need to do a simple search and replace in. I have been doing it in a text editor (EditPlus) by opening 500 files at a time, doing a global search/replace, saving all, closing, etc. But, that's taking literally hours to do and it's boring and tedious and I already have done it once today and need to do it again because all the files got refreshed. Is there a way to do this via the Bash command line? Here's the details:
Find onchange="document.location ='/products/view.html/view/'+this.value"
Replace it with onchange="alert('Not implemented')" style="display: none"
All of the files have a .HTM extension, but they are nested in several sub directories.
EDIT - I'm on a Mac and would prefer a *nix based solution.

A: The base command for you case looks like this:
sed -i 's|oldvalue|newvalue|g' file1 file2 file3

If all your file are in the directory ~/foo/bar/, what you want to do is:
cd '~/foo/bar/'
find . -type f | xargs sed -i "" "s|onchange=\"document.location ='/products/view.html/view/'+this.value\"|onchange=\"alert\('Not implemented'\)\" style=\"display: none\"|g"

EDIT: the glob (* as file name) can be problematic with very very much files and don't go in the child directories. In this case, change the last line.
EDIT 2: with BSD sed (the one used on MacOS X) -i needs an argument. BTW using xargs. Thanks to @Dennis Williamson

A: Since EditPlus is a Windows editor i'm guessing you want a Windows shell solution.
You can get sed variants for Windows, but here's a PowerShell solution that recursively finds all *.HTM files, replaces "this" with "that", then saves the file.
gci -Include *.HTM -Recurse | % {
  (gc $_) -replace "this","that" | sc -path $_ }

Using your strings makes things a bit more tortured, since you have embedded double- and single-quotes, along with regular expression characters. The quotes are escaped with backticks (`) and the regex characters with backslashes (\).
gci -Include temp*.HTM -Recurse | % {
  (gc $_) -replace "onchange=`"document\.location `
  =`'/products/view\.html/view/`'\+this\.value",`
  "onchange=`"alert(`'Not implemented`')`" style=`"display: `
  none`"" | sc -path $_ }

Powershell is included with Windows 7, and can be downloaded for XP and above.
There's a vbscript single-file solution at StackOverflow i posted in response to "Is there any sed like utility for cmd.exe?" That question contains many answers with suggestions for Windows command-line sed solutions.
