Link to home
Start Free TrialLog in
Avatar of thomkat2295
thomkat2295

asked on

How do I find and replace text strings in a series of html fies

I need to find a batch file or script to change a series of text strings in a number of html Page files within a given folder, for example:

Replace: href="Template
With:       href="suspsyst
Replace: <embed type="image/svg-xml" src="
With:       <img src="
Replace: <table border="0" cellspacing="0" cellpadding="5" width="730" bgcolor="#ffffff" xmlns:fo="http://www.w3.org/1999/XSL/Format">
With:       <table border="0" cellspacing="0" cellpadding="5" width="1000" bgcolor="#ffffff" xmlns:fo="http://www.w3.org/1999/XSL/Format" height="87%">
Replace: <img src="../common/img_num/link.gif" width="15" height="15" border="0" style="vertical-align:middle;">
with:         (no text, effectively deleting the string)

Or a script that ca be run in Golive
Avatar of omesie
omesie

download a copy of Notepad++ and there's an option there to scan all files in entire folders and replace specific text to whatever you like.
Sorry, this might help. (or just do a google search)
http://notepad-plus-plus.org/
Avatar of knightEknight
Download and unzip this utility:

http://www.paulslore.com/utils/chgstr.zip

Then you can change all of your HTML files (including sub-directories) like this:

CD \parentFolder
chgstr.exe  "Replace: href=\"Template"  "href=\"suspsyst"  *.html  /s
ooops, I left the word "Replace:" in the search string by mistake - but you get the idea.

Run chgstr.exe /?  to see the help screen.

Generally it works like this:

  chgstr.exe  "searchString"  "replaceString"  filespec  [/options]
I know DOS was mentioned in the keywords of your question. But I have used 12Ghosts Replace via a .bat file or command line
1,000's of time to do millions of S&R jobs.  

It is fast, and can handle very large file and a large amount of them w/o screwing up.


12Ghosts

Taken From Help file in 12ghosts:
Command line options
To repeatedly replace the same strings in the same set of files or folders call 12-Replace via command line options. This makes it easy to create a shortcut or batch file to replace several phrases at once.

Syntax:
12replace.exe "path" "search" "replace" [/replaceall] [/nosound] [/sub] [/only] [/case] [/word] [/contents]

Example: 12replace.exe "C:\My Documents\Data" "Date: 11/16/2006" "Date: 01/11/2007"

Avatar of thomkat2295

ASKER

Hi Guys
Thanks for yor speedy responses, I will work on each as I have the time.

As I will need to change up to 20 text strings in each file in a foder containing at least 30 files.
I was hoping to do this with just one batch, script or exe file.

Currently in Golive I can do a find replace on multiple files in a folder, however I have to set up each find replace individualy some 20 times. Then I need to go through the same process for the next foder, hence the need for a batch or sript.

I hope this better explains my objective
With that few files.
Just USE TEXTPAD5 .
(Free Trial)
Drag all the files into Textpad5.

Click F8
Check ALL DOCUMENTS
Insert the Search and Replace strings .


Granted You will have to do this for each instance
But it will do all the files at once.


With a DOS script. I would worry. It would take abit of luck and alot of guessing.
To write a S&R script for files with so many UNKOWN variables.


Also 12ghosts is FAST and good and will recurse the folders.

Hope this helps.

Regards
SOLUTION
Avatar of knightEknight
knightEknight
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
... and if you have more than one filespec, it will take that too:

  chgstr.exe  "searchString1"  "replaceString1"  *.html  *.aspx   *.inc   /s
and note that if your search string contains double-quote characters, escape them with \

   chgstr.exe  "href=\"Template"  "href=\"suspsyst"  *.html  *.aspx  /s
Hi knightEknight

Thanks for your advice so far. however I am having a bit of dificulty in getting it to work due to the IDtenT error. Firstly, where should the chgstr.exe file reside, what folder? Can you provided me with and example of a batch file containing the following in a text file.

  chgstr.exe  " href="Template "  "href="suspsyst"  *.html /s
  chgstr.exe  "<embed type="image/svg-xml" src="  "<img src="  *.html /s
  chgstr.exe  "<table border="0" cellspacing="0" cellpadding="5" width="730" bgcolor="#ffffff" xmlns:fo="http://www.w3.org/1999/XSL/Format">
"  " <table border="0" cellspacing="0" cellpadding="5" width="1000" bgcolor="#ffffff" xmlns:fo="http://www.w3.org/1999/XSL/Format" height="87%">"  *.html /s

When saving the text file what extention shuold it have, and how is it executed.

While I am able to acheive a find replace on multiple files I currently have to do it on a line by line basis.
Or is it that to do the work via bat or other executable is not possible.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Why delete this question?
knightEknight, did you read my recommendation?
My bad, the email said it would be deleted - sorry.
Hi guys, I have been on leave for the past 6 weeks and have only just caught up on all the posts. As soon as I have some time I will write a scrip bases on the post by billprew on the 02/11 taking account of the added comments by knightEknight.  

On the basis of billprew's script all " marks must be preceeded by a \ . I will work on it over the weekend and hopfuly report my sucess.
Starting the auto-close procedure on behalf of the Question Author, to implement the recommendations from the participating Expert(s).


-----
Everyt'ing is everyt'ing,

Mod_MarlEE
Community Support Moderator