What is the best tool for finding and replacing regular expressions over multiple files?

Preferably, if possible, tools.

In addition, the ability to search for multiple regular expressions and each substitution with different lines will be a bonus.

+20
regex replace search
Sep 19 '08 at 14:06
source share
19 answers

Perl Seriously, this makes sysadmin things a lot easier. Here is an example:

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

+32
Sep 19 '08 at 14:13
source share

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/" "{}" ";" 
+18
Sep 19 '08 at 15:19
source share

Textpad does a good job of this on Windows. And this is a very good editor.

+6
Sep 19 '08 at 14:11
source share

Unsurprisingly, Perl does an excellent job of this, combined 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 effective without a race condition):

 for file in @filelist ; do cat $file | sed "s/pattern/result/" > /tmp/newfile mv /tmp/newfile $file done 
+4
Sep 19 '08 at 14:16
source share

The Emacs directory editor has a `dired-do-query-replace-regexp 'function for finding and replacing a regular expression over a set of marked files.

+4
Sep 19 '08 at 14:17
source share

I wrote a free command line tool for Windows to do this. It is called rxrepl , it supports unicode search and file. Some of them may be useful.

+4
Jan 23 '13 at 19:50
source share

On Windows, I liked WinGrep

On Ubuntu, I use Regexxer.

+3
Sep 19 '08 at 14:10
source share

For Mac OS X, TextWrangler does the job.

+2
Sep 19 '08 at 14:12
source share

To search and replace in multiple files on Windows, I found rxFind to be very useful.

+2
Oct 14 '08 at 18:09
source share

My personal favorite is PowerGrep from JGSoft. It interacts with RegexBuddy , which can help you create and test regular expressions, automatically support all changes (and provides undo options), provides the ability to parse multiple directories (with file name templates), and even supports file formats such as Microsoft Word, Excel and PDF

Powergrep screenshots

+2
Jun 07 '09 at 21:19
source share

I would go for bash + find + sed.

+1
Sep 19 '08 at 14:11
source share

Wim for salvation (and the president ;-)). Try:

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

(I really love the Vim -c switch, it's magic. Or if you are already in Vim and opened files, for example:

 vim <list_of_files> 

Only problem:

 :bufdo! s:foo:bar:gci 

Of course, sed and perl also capable. NTN.

+1
Sep 19 '08 at 14:26
source share

I have the luxury of Unix and Ubuntu; In both cases, I use gawk for everything that needs to be searched and replaced in turn, especially for line by line substrings. Recently, it was the fastest for processing 1100 changes in millions of lines in hundreds of files (one directory) On Ubuntu, I am a fan of regexxer

  sudo apt-get install regexxer 
+1
Jun 12 '09 at 21:13
source share

There is a free alternative on Windows that works best: Notepad ++

Go to the "Search" β†’ "Find Files" section. You can specify a directory, a file template, set regular expressions, then look up matches and finally replace all files recursively.

+1
Mar 22 '12 at 18:27
source share

I like this tool:

http://www.abareplace.com/

Gives you a "how you type" preview of its regular expression ... FANTASTIC for those who are not very versed in RE ... and very quickly change hundreds or thousands of files at a time ...

And then give UNDO your changes as well ...

Very nice...

Patrick Style - http://www.podiotools.com

+1
Jan 28 '13 at 15:26
source share

If "text panel" is a valid answer, I would suggest Sublime Text to go down.

Editing multiple cursors is an even more efficient way to make replacements in general that I find, but its "Find in Files" "is the top level for replacing voluminous regular expression / regular search.

+1
Jul 10 '15 at 20:17
source share

jEdit regex search & file replacement is pretty decent. However, slightly overdo it if you only use it for this. It also does not support the variable you requested.

0
Sep 19 '08 at 14:12
source share

I found the RxFind tool useful (free OSS).

0
Jun 07 '09 at 21:12
source share

Brackets (source code, deb / Ubuntu, OSx and Windows) has a good visualization of the results, allowing them to individually apply the replacement. You can search for standard or case-sensitive texts and regular expressions. Very important: you can exclude file and directory templates in the search.

0
Apr 10 '16 at 14:32
source share



All Articles