How To “Find And Replace” Words In Multiple Files

notepad1   How To Find And Replace Words In Multiple FilesI have been using Notepad ++ for years as my Windows Notepad replacement.

It does highlighting and line numbers, these were my first reasons for using it. Notepad ++ has been my best friend for writing scripts and HTML files.

Now I had a new challenge and my buddy Mike told me that Notepad ++ would be my easiest and FREE solution.

Here was my dilemma – I had 8,342 HTML files and I needed to replace some text on every single page to reflect a company’s identity tweaking. The company was mostly adult-oriented before and now they are trying their hand at mainstream. They needed to remove the word ADULT from their company name every where throughout their site. Now your friendly neighborhood admin was not going to be doing this manually – that was for sure. So I fired up Notepad ++ and searched for this magic option.

Sure enough there it was on the search menu – the option that was going to make my life easier – “Find In Files”.

Using this awesome feature I am able to have Notepad++ find all files with the word I choose in them. It then shows me the results of my search. 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”.

notepad2   How To Find And Replace Words In Multiple Files

notepad3   How To Find And Replace Words In Multiple Files

After you find all your instances and have all the files open in Notepad ++ you can then click over to the replace tab – now you will see a option to replace throughout ALL OPENED FILES! Sweet!

notepad4   How To Find And Replace Words In Multiple Files

I am guessing that some of you out there have never heard of or used Notepad ++ before. So let me run down the basic features with you. If you are a scripter, coder or any type of programing monkey this program will make you salivate!

Check it out, Notepad ++ has:

  • Syntax Highlighting and Syntax Folding
  • WYSIWYG
  • User Defined Syntax Highlighting
  • Auto-completion
  • Regular Expression Search/Replace supported
  • Full Drag “ËśN’ Drop supported
  • Multi-Language environment supported
  • Brace and Indent guideline Highlighting
  • Macro recording and playback
  • Bookmarks

Do you have another way to find and replace throughout a slew of files? After completing this task I was told about another free application that might have made my life even easier… It is called BkReplaceEm and stay tuned for my review!

The comments were closed because the article is more than 180 days old.

If you have any questions related to what's mentioned in the article or need help with any computer issue, ask it on MakeUseOf Answers—We and our community will be more than happy to help.

19 Comments -

GeekLad

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.

Miguel Guhlin

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

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.

ontguy

PSpad has a similar feature:

bcnubes

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

Aibek

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

Karl L. Gechlik

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!

DrUskov

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.

Ted Murphy

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.

fung

textCrawler will do the job better.

Miguel Guhlin

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

Miguel Guhlin

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

Abhigyan Agrawal

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.

Chris Hall

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.

spuri

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

spuri

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

Andy

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.

Ashley Thomas

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!