Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Global Find/Replace 2

Status
Not open for further replies.

cwsstins

MIS
Aug 10, 2004
412
US
Is there a way to search for a particular piece of text throughout an entire site, rather than looking through each individual page? I need to change a "company name" to a new name for a lot of pages and I'm wondering the easiest way to do it.
 
If you have a text editor like Textpad, you can search for instances of a phrase in the files, and the results will be a list of the files that contain that phrase, and the lines the phrase is on. Clicking on the line in the search results will open that file in Textpad an put the cursor at that line. Once you have all the files open, it's easy to do a search and replace in all documents.

I imagine there are other text editors that will perform the same way, even free (Textpad is free to try, but asks you to buy if you want to continue to use it).

Lee
 
Ok! This won't completely automate it but it makes it a bit simpler.

1. make a new folder, say c:\aaa and copy all html files to it.
2. from a command prompt change to that directory eg: cd\aaaa
3. from the prompt type:
dir *.* /b > massedit.txt
4. massedit.txt will contain a list of files in the directory.
5. back in the gui world edit massedit.txt with notepad and paste the word 'NOTEPAD ' to the beginning of each line.
6. Delete the line containing massedit.txt
7. Rename massedit.txt to massedit.bat and click on it.

Now each file will appear in notepad in turn as you edit save and close each one.

Use replace all. Note that if you swipe the first occurance of old business name (don't copy) when the replace window comes up it will have the old name in the from field. If you keep the new name in the clipboard you can right mouse and paste it into the to field.

Clive
 
It'd be a REAL pain to use Notepad if you have more than a few pages. A decent text editor is SO much nicer, and this is one of the reasons. If you do a search for "free text editor" on Google, you'll get a lot of good links to check out.

As well, here are some of my favorite links for things like that:




Lee
 
On linux/unix you'd use the [tt]grep[/tt] command to do this. A quick Google found a (shareware) windows version of this tool at . I've not used it, but it looks pretty nifty. I've not used it, but it looks pretty nifty.

Personally, I've used the "Search Disk" function in Notetab Pro to do this sort of thing, though I've not found it 100% reliable when searching for multi-line blocks of text (it's safer to open all the documents in question and do a global search/replace over all of them). Opening each document individually in Notepad sounds like an insane amount of extra work to acheive this object.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Hi

I know, Windows peoples prefer GUI tools, but while Chris already mentioned [tt]grep[/tt], let me complete the list : [tt]awk[/tt] has a nice Windows implementation, called [tt]awk95[/tt]. This can make the replacement from command line, without user interaction. Works with one file per call, but is easy to automate the task.
Code:
awk95.exe "{gsub(\"Old Company Name\",\"New Company Name\");print}" index.html > rewritten\index.html
( Above code tested on Windows '98, but should work on other versions too. )

As far as I know, is free :

Feherke.
 
Not trying to out-do anyone but I found this interesting and a new use for EDLIN the original DOS editor which is still in the windows OS.

changeAll.bat
Code:
@ECHO OFF
    FOR %%I IN (*.HTM) DO CALL EDLIN %%I < response.txt
:END

Translation: For all files, in the current directory, with an HTM extension, call EDLIN for each file in turn using the response file RESPONSE.TXT


response.txt
Code:
1,99rOld CompanyNew Company
e

Translation: For lines 1 thru 99 replace Old Company with New Company and save and exit

Notice that there is a special character (hex 1c) in the first line. It doesn't seem to upset notepad if you paste and edit the file there.


Clive
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top