How to Find and Replace Words in Multiple Files
Pinterest Stumbleupon Whatsapp
Advertisement

What do you do if you have to replace a single word in dozens, or even hundreds or thousands, of text files? You keep calm and download Notepad++ or Replace Text. These two utilities will do the job in seconds.

It’s a dilemma common among developers and programmers. Imagine you’re managing a project with hundreds or thousands of files. When a product name that appears on almost every page changes, you can hardly go through each page to manually search and change the name. No, you’re smarter than that.

You fire up Google, you find this article, and you learn about a solution that only takes seconds.

How to Edit Multiple Files in Bulk

You can either use Notepad++ or a dedicated tool called Replace Text to bulk-edit How to Use Windows Batch File Commands to Automate Repetitive Tasks How to Use Windows Batch File Commands to Automate Repetitive Tasks Do you frequently execute boring and repetitive tasks? A batch file might be exactly what you’re looking for. Use it to automate actions. We'll show you the commands you need to know. Read More your files.

Notepad++

First, allow Notepad++ to find the word in all the files you need to edit. Open Notepad++ and go to Search > Find in Files… or press CTRL+SHIFT+F. This opes the Find in Files menu.

Under Find what:, enter the word or phrase that you need to change. Under Replace with:, enter the new word or phrase. Finally, set the Directory: where the affected files are located, so that Notepad++ knows where to search.

How to Find and Replace Words in Multiple Files Notepad Find in Files

You can also use advanced settings, which I’ve outlined further down. When all is set, click Find All if you need to double-check the hits or Replace in Files if you want Notepad++ to immediately apply the changes. Depending on the number of files Notepad++ is searching, this can take a few seconds.

If you went with Find All, you’ll get a list of hits. Remove all the files you don’t want to edit by selecting them and pressing DEL, then right-click the remaining files and choose Open all.

Now go to Search > Replace or press CTRL+H, which will launch the Replace menu. Here you’ll find an option to Replace All in All Opened Documents.

How to Find and Replace Words in Multiple Files Notepad Replace

Again, you can make several advanced settings, as explained below.

Advanced Search and Replace Settings in Notepad++

Under Find in Files, you can add Filters to search only in certain file types. For example, add *.doc to search only in DOC files. Likewise, you can search for files with a certain name, regardless of file type. Add *.* to search any file name and type.

When you choose a directory with sub-folders, check In all sub-folders and In hidden folders to search those, too. You might also want to check Match whole word only, so you don’t accidentally edit a partial match.

The Search Mode in both the Find in Files and Replace menus allows you to make advanced searches and replacements. Select Extended if you are using extensions, for example to replace a character with a new line (\n). Select Regular expression if you’re using operators to find and replace all matching words or phrases. You can stick with Normal if you’re just replacing text with text.

Replace Text

With Replace Text, you can set up a Replace Group to add multiple files and/or directories and multiple replacements.

To start, create a new group. Go to Replace > Add Group, and give your group a name.

Right-click your group and select Add File(s)… to add the files and/or folders you want to edit. In the Files / Folder Properties, select your Source Type, i.e., a single file or folder, then choose the Source File / Folder Path. If you choose to add a folder, you can also include and exclude file types by adding them to the Include File Filter or Exclude File Filter rows. Click OK when you’re done.

How to Find and Replace Words in Multiple Files Replace Text Files Folder Properties

To add multiple files or folders, repeat the above step.

Replace Text’s best feature is that you can choose a destination that’s different from the original location. In the File / Folder Properties, switch to the Destination tab and choose your desired Destination File / Folder Path.

Now that you’ve set up your group, it’s time to define your replacements. Select your group and go to Replace > Search/Replace Grid > Advanced Edit… Now you can add the Search Text and Replace Text. Be sure to look in the drop-down menu at the bottom to customize the search and replace options.

How to Find and Replace Words in Multiple Files Replace Text Advanced Edit

Like with Notepad++, you can use advanced search strings and operators How Search Engines Work & Ways to Improve Your Search Results How Search Engines Work & Ways to Improve Your Search Results Tired of searching a bunch of times to find what you want? Here's how search engines actually work and what to do to make your searches faster and more accurate. Read More . Unlike Notepad++, you can add as many search and replace instances as you like and Replace Text will run through all of them when you run the process.

To make the replacements, go to Replace > Start Replacing or press CTRL+R.

About the Tools

What Is Notepad++?

Notepad++ is a free source code editor and Windows Notepad alternative. It’s released under a GNU General Public License, making it an open-source Open Source vs. Free Software: What's the Difference and Why Does It Matter? Open Source vs. Free Software: What's the Difference and Why Does It Matter? Many assume "open source" and "free software" mean the same thing but that's not true. It's in your best interest to know what the differences are. Read More  tool.

Furthermore, Notepad++ is a lightweight application that conserves resources, which makes it good for the environment:

By optimizing as many routines as possible without losing user friendliness, Notepad++ is trying to reduce the world carbon dioxide emissions. When using less CPU power, the PC can throttle down and reduce power consumption, resulting in a greener environment.

Here’s a small selection of Notepad++ features that make this the perfect tool for writing and editing (code):

  • Numbered lines for easier navigation.
  • Automatic and customizable highlighting and folding of coding syntax.
  • Support for Perl Compatible Regular Expression (PCRE) search-and-replace.
  • Auto-completion that includes word completion, function completion, and function parameters hint.
  • A tabbed interface that lets you work with multiple documents in parallel.
  • Editing of multiple lines at once, using either CTRL+mouse-selection or column editing.

What Is Replace Text?

Replace Text is a whole lot simpler than Notepad++. It does one job: replacing text. Ecobyte, the company behind Replace Text, is mindful of its impact. Hence, the software with a cause comes with an unusual EULA:

How to Find and Replace Words in Multiple Files ecobyte EULA 670x452

Unfortunately, Replace Text is no longer supported and no help file is available in Windows 10. I have covered it anyhow because it offers more advanced features than Notepad++ for this particular application.

Search and Replace Made Easy

One of the two utilities above should do the job for you. If you only have a simple search-and-replace job or if the additional features of Notepad++ sound useful, you should give it a try. If you need to edit not only multiple files How to Batch Rename & Mass Delete Files in Windows How to Batch Rename & Mass Delete Files in Windows Are you pulling your hair out over how to batch rename or delete hundreds or thousands of files? Chances are, someone else is already bald and figured it out. We show you all the tricks. Read More , but also need to make multiple different replacements, it’s worth looking into Replace Text.

Which one did you choose and did it work as prescribed? Have you found other tools that can search-and-replace text? Let us know in the comments below!

Image Credit: Fabrik Bilder via Shutterstock.com

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. sagar dahal
    October 5, 2017 at 12:01 pm

    I've made a small tool in my free time to do just that. It can also replace string in file and folder names.
    Here's the link to the source code and the executable.
    https://github.com/chaosifier/StringReplacer

    • Tina Sieber
      October 12, 2017 at 10:26 pm

      Thank you for sharing, Sagar!

    • Jake
      November 28, 2017 at 1:56 pm

      Doesn't work and it corrupts the document, making it unreadable. Luckily I backed it up before I tried.

      • Sagar Dahal
        November 28, 2017 at 2:06 pm

        Pleas note that this app was made only for replacing text in non-formatted text files. For example, files with extensions like .html, .css, .js, .cs etc. not file formats like .doc, .docx, .pdf etc which include special formatting.

  2. Josh
    May 2, 2017 at 5:26 am

    Any ideas on how to do find and replace with multiple PDF files on Mac?

    • Tina Sieber
      May 4, 2017 at 5:30 pm

      Wish I could help with that, Josh! Not a Mac user myself.

    • Jake
      November 28, 2017 at 1:58 pm

      Only possible using Acrobat. Such an unusual requirement that I doubt it's realistically possible.

  3. Meakai
    February 14, 2016 at 7:45 pm

    I was trying to open 5000+ with notepad++, then I went searching and found this. The new version of notepad++ allows you to choose the directory to "find and replace".

    Thank you x5000

  4. Anonymous
    October 2, 2015 at 12:35 pm

    Thanks a lot mate, i Notepad++ new version can replace word in all file directly without opened :D
    once again thanks :D

    • Anonymous
      October 2, 2015 at 12:35 pm

      [edited]
      Thanks a lot mate, in Notepad++ new version can replace word in all file directly without opened :D
      once again thanks :D

  5. Anonymous
    August 28, 2015 at 9:01 pm

    Thanks man. You save my life.

  6. Anonymous
    July 13, 2015 at 5:22 am

    Thank you so much for the tutorial.

  7. Luis
    April 13, 2015 at 12:57 pm

    A long time ago, some smart folks thought about this problem (and other similar problems) and asked themselves the question: would it be better to have a lot of commands and tools for each type of task, or would it be better to have just a tiny set of tools that do just a couple of things each, and can be organized in a sequence, in different ways, so that you can solve lots of different problems? (kind of like lego pieces). They decided the little tools was a better idea. This was so good, that even after 40 years of advances in computing no one has come with anything better. If you learn those tools, you will be able to solve a large number of things, almost like magic. To do it: download Cygwin, and install/learn sed and awk (very simple to do) and learn about pipes ( | )

  8. Amanda Sellers
    January 28, 2015 at 7:34 pm

    I just ran across this when I was looking for a way to batch edit text files. We use a program that creates them, but they need to be modified before they can be sent to our shop. This worked perfectly for what I need to do and I already had Notepad++ on my PC. It's also going to help some co-workers save some time as well. Thank you!

  9. kenny , scotland
    December 16, 2014 at 10:43 am

    Actually Dreamweaver does this with a large site of html files. but it wouldnt work with pure text files when i tried it.

    Well they were really .ahk files for auto hot keys.

    Been using Dreamweaver for years to manage 1500+ html files and it is just great at find / replace over entire current local site....

    Going to try the notepad + option for my text files ....

    I have some changes needed in about 60 text files, and was looking for an easy option.

    Thats how I found this old entry.... but someone might find it useful..

  10. Ashley Thomas
    June 26, 2009 at 11:23 pm

    OhMyGod I Love You!
    I was so stressed out because I got a new website, and I had to change all my links,
    but this program did it in like 10 seconds!
    Thank you so much!

  11. Andy
    February 27, 2009 at 2:27 pm

    To open many documents for the bulk find replace functionality use File > Open. Then when the file manager window comes up, highlight all the documents you want to edit. Once that is done, then you can follow Karl's steps above.

  12. spuri
    October 28, 2008 at 9:40 am

    I think this won’t work with UTF-8 file encoding… :(
    Do you know a newer clone?

  13. spuri
    October 27, 2008 at 9:41 am

    Do you know a free solution to make multiple replace in multiple files?
    I mean replace worldA with worldB and exA to exB in multiple files.
    Thanks

  14. Chris Hall
    October 24, 2008 at 2:10 pm

    Certainly, having to have all the 8000+ files open to work is not an ideal solution. HTML editors like Dreamweaver or CoffeeCup HTML Editor have had features like this for a while to make mass changes to files in a certain directory.

  15. Abhigyan Agrawal
    October 24, 2008 at 11:46 am

    While notepad++ is good for somethings, it is not the best solution for such a problem.

    A simple python script would do the trick much easily and neatly.

    import fileinput, glob, string, sys, os
    from os.path import join

    text_search = 'what ever you want to search'
    text_replace = 'what ever you want to replace with'

    path = join ('directory to search',"*")
    files = glob.glob(path)

    for line in fileinput.input(files,inplace=1):
    lineno = 0
    lineno = string.find(line, stext)
    if lineno > 0:
    line =line.replace(stext, rtext)

    sys.stdout.write(line)

    You can of course change this so that it takes search text etc. as command line input.

  16. Miguel Guhlin
    October 24, 2008 at 2:39 pm

    Thanks to MakeUseOf.com, I've discovered many new text editors. Here's my illustrated walkthrough of BK Replace Em, which worked well for my purposes.

    mguhlin.net/2008/10/in-parallel-file-search-and-replace.html

    With appreciation,
    Miguel Guhlin
    Around the Corner
    mguhlin.net

  17. Miguel Guhlin
    October 24, 2008 at 2:37 pm

    Howdy! Thanks to MakeUseOf.com, I now have several programs to get the job done. In the meantime, here is my illustrated experience with BK ReplaceEm! It worked for me, so thanks to MakeUseOf.com!

    mguhlin.net/2008/10/in-parallel-file-search-and-replace.html

    Best wishes,

    Miguel Guhlin
    Around the Corner-MGuhlin.net
    mguhlin.net

  18. fung
    October 23, 2008 at 7:03 am

    textCrawler will do the job better.

  19. Ted Murphy
    October 22, 2008 at 2:50 pm

    Notepad++ sounds like a nice free alternative. I use the shareware app Textpad all the time, which may be comparable. DrUskov's Notetab sounds excellent as well; I may give that a try.

    When I am coding html, however, and dealing with an actual website, I use HomeSite 4.5.2. I've used it for years, and I just keep installing the app along with license key over and over. Its now an Adobe product, and the price is a pretty steep $99 for the latest 5.5 version.

    If I were starting from scratch, I would probably pony up and buy a new version of Homesite. I'd kick and scream a bit first. This seems to be the case with all of Adobe's products -- expensive, but they work.

  20. DrUskov
    October 21, 2008 at 11:36 am

    I've never used Notepad++, but for my money Notetab (http://www.notetab.com/) is the best best. It's a heavy-duty text editor that I've used for 8 or 9 years, and I'm not sure why more people haven't heard of it. It is probably the most useful program I use. Period. Better than Excel even. And I love Excel.

    It replaces MS Notepad if you want, or stands alone. Clips (their term for macros) are insanely useful. I use them all the time. In fact, I just ran across the problem of wanting to make chanes to 1,400 HTML files I downloaded. Not only could I search/replace with regular expressions through all 1,400 files, I could open all 1,400 files individually or dump them all into a single document (and if I so desired remove all HTML coding, or just keep the URLs). MS Word would have a coronary if I tried that, but Notetab is scorching fast. I think I've had up to 800,000 lines of text in a document before without any apparent slowdown.

    Maybe the single most useful feature, and worth the download alone, is the ability to turn a text document into an infinite paste board. Press Ctrl+Shift+P for any single tab and it vacuums up any text you copy (no pasting needed). You can even define what you want Notetab to insert at the end of the pasted text (line break, paragraph, tab, asterisks, whatever). Great for superfast "scraping" of text from websites, particularly when you combine with Firefox's Autocopy Add-On. Sweet.

    Notetab comes in 3 flavors. I started with the free downloadable version, but forked over the $35 bucks to the get the Pro version (gives you multiple undo's, and a ton of other stuff). I've literally used it to make thousands of dollars because of the functionality it provides that I simply can not replicate in Word, Excel, or anywhere else as near as I can tell. And I'm always looking for other options, but can't find anything better.

  21. Aibek
    October 21, 2008 at 10:46 am

    I wonder how did you manage to open 8K files at the same time :-)

    • Karl L. Gechlik
      October 21, 2008 at 12:25 pm

      A WHOLE LOT OF CLICKING!

      But wait I did just find a AMAZING alternative that does not require you to open all the files you want to search/replace through. It is called BK ReplaceEm 2.0 and at 413kb it can't be beat! I just finished my article on it and it will be up for everyone to read tomorrow!

  22. bcnubes
    October 21, 2008 at 12:56 pm

    I have never used it but it looks like Portable HTML batch was designed to do the same type thing.

    Portable HTML batch edit-
    A unique tool specifically designed to help webmasters, developers and any others to batch convert or operate on multiple files at the same time. It is specifically designed to operate on HTML files but you can use it on any type of files including binary ones.

    app-stick.com/proddetail.php?prod=HTMLbatch

  23. ontguy
    October 20, 2008 at 10:18 pm

    PSpad has a similar feature:

  24. Miguel Guhlin
    October 20, 2008 at 9:34 pm

    Howdy! NotePad++ looks like a great editor, but you didn't point out HOW to open all files found in the search. I'm trying your step by step to no avail...this is where more how to is needed:

    >Once I click on all the instances I want to change, it will open those files. I can then do my >“replace on all open files”.

    If you have 7000+ files, you have click on everything? I tried that and no luck.

    Thanks in advance,

    Warm regards,
    Miguel Guhlin

    • Karl L. Gechlik
      October 21, 2008 at 12:26 pm

      Sadly opening the files is manual but stay tuned for a review of another free utility called BK ReplaceEm 2.0 that will do it automagically.

  25. GeekLad
    October 20, 2008 at 8:06 pm

    As a programming "hobbyist" (I don't consider myself to be good enough to call myself a programmer), I really love Notepad++. My three favorite features are syntax highlighting, macros, and regular expressions in search/replace. The macro functionality is stupid easy to use and using regular expressions for search/replace can be really handy. Syntax highlighting makes it easier to keep code formatted properly and ensuring blocks of code are properly terminated.