2

I have a few thousand files that I need to search and replace. Is there a software that can open a directory of files, scan those files and then search and replace? I'm aware that you can script something like this. However, I have no interest and prefer to use something that is already made.

1
  • 1
    which OS do you use?
    – akira
    Oct 23, 2011 at 5:37

3 Answers 3

3

If you're using Linux you can pipe the results of a find command into sed to perform the replace.

find . -name '*.txt' -print0 | xargs -0 sed -i 's/searchpattern/replacepattern/'

This will find every file in your current directory and below (. is your current directory) and replace instances of searchpattern with replacepattern.

3

If you're using Windows, you could try to use NotePad++.
There's a tab in its Replace window that scans for files in a folder (you can choose an extension to filter) and do search/replace automatically.

Just note that doing thousands of files can take a very long time. This depends on the specifications of your computer. Just ensure you have a backup of the files you are going to find and replace in case Notepad ++ crashes and you lose data.

2
  • Strange. I contributed to the second part of the answer and it says Diago did it.
    – Sam
    Oct 23, 2011 at 11:11
  • 1
    @Sam: looking at the edits history, I saw you put your contribute right after mine, without blank lines. Diago fixed it. Thanks to everybody who made my answer better, thanks a lot!!
    – Marco
    Oct 23, 2011 at 11:41
0

I often work on Windows and various flavours of Unix, and for replacing text I use sfk. For example, to replace "foo" with "bar" in all .txt files in folder logfiles and all subdirs, type the following:

sfk replace -pattern /foo/bar/ -dir logfiles -file .txt

It will do a simulation run. Add the -yes switch to actually replace the text.

2
  • Are you associated with this project at all or it's developer? If so please disclose this per the FAQ or this might be considered SPAM. Jul 18, 2012 at 23:02
  • no, I just use the program often for my daily work.
    – pgarcia
    Jul 19, 2012 at 2:24

You must log in to answer this question.