Preferably free tools if possible.
Also, the option of searching for multiple regular expressions and each replacing with different strings would be a bonus.
Preferably free tools if possible.
Also, the option of searching for multiple regular expressions and each replacing with different strings would be a bonus.
Textpad does a good job of it on Windows. And it's a very good editor as well.
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.
Perl. Seriously, it makes sysadmin stuff so much easier. Here's an example:
perl -pi -e 's/something/somethingelse/g' *.log
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
done
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
done
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.
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 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