Preferably free tools if possible.

Also, the option of searching for multiple regular expressions and each replacing with different strings would be a bonus.

+1  A: 

Under Windows, I used to like WinGrep

Under Ubuntu, I use Regexxer.

+1  A: 

I'd go for bash + find + sed.

Rafał Dowgird
+3  A: 

Textpad does a good job of it on Windows. And it's a very good editor as well.

Couldn't agree more about TextPad being an excellent editor (my personal favourite). However, whilst it does search over multiple files (and very quickly at that) it doesn't do search and replace over multiple files.
Umber Ferrule
Yes it does. What you have to do is right-click and select "Open All" in the search results. This will open all the found files. Then in the Replace dialog, click the "All Documents" radio button for where to do the replacing. After it finishes, click "Save All".
+1  A: 

For Mac OS X, TextWrangler does the job.

Especially because it provides visual feedback and allows you to review the changes it made before saving them back to files. I prefer BBEdit, its bigger brother, though, for its larger amount of functionality. Isn't free like TextWrangler, though
Thomas Tempelmann

jEdit's regex search&replace in files is pretty decent. Slightly overkill if you only use it for that, though. It also doesn't support the multi-expression-replace you asked for.

Oliver Giesen
+14  A: 

Perl. Seriously, it makes sysadmin stuff so much easier. Here's an example:

perl -pi -e 's/something/somethingelse/g' *.log

Alex Fort
+3  A: 

Unsurprisingly, Perl does a fine job of handling this, in conjunction with a decent shell:

for file in @filelist ; do
  perl -p -i -e "s/pattern/result/g" $file

This has the same effect (but is more efficient, and without the race condition) as:

for file in @filelist ; do
  cat $file | sed "s/pattern/result/" > /tmp/newfile
  mv /tmp/newfile $file
Craig Trader
I also like to use "find -iname" with thatm to get a recursive search.
+2  A: 

Emacs's directory editor has the `dired-do-query-replace-regexp' function to search for and replace a regexp over a set of marked files.


Vim for the rescue (and president ;-) ). Try:

vim -c "argdo! s:foo:bar:gci" <list_of_files>

(I do love Vim's -c switch, it's magic. Or if you had already in Vim, and opened the files, e.g.:

vim <list_of_files>

Just issue:

:bufdo! s:foo:bar:gci

Of course sed and perl is capable as well. HTH.

Zsolt Botykai
+10  A: 

sed is quick and easy:

sed -e "s/pattern/result/" <file list>

you can also join it with find:

find <other find args> -exec sed -e "s/pattern/result/" "{}" ";"
I agree on the quick.... and it is easy only for a given value of easy. Anyways +1 ;)
Mario Ortegón
+1  A: 

For find-and-replace on multiple files on Windows I found rxFind to be very helpful.


I've found the tool RxFind useful (free OSS).

Martin R-L
+2  A: 

I have the luxury of Unix and Ubuntu; In both, I use gawk for anything that requires line-by-line search and replace, especially for line-by-line for substring(s). Recently, this was the fastest for processing 1100 changes against millions of lines in hundreds of files (one directory) On Ubuntu I am a fan of regexxer

 sudo apt-get install regexxer