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="">
With:       <table border="0" cellspacing="0" cellpadding="5" width="1000" bgcolor="#ffffff" xmlns:fo="" 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
Who is Participating?
Bill PrewConnect With a Mentor Commented:
(not for points, just killing sometime...)

Firstly, where should the chgstr.exe file reside, what folder?

You really have three choices here, but let's try the easiest one.  Place the chgstr.exe file in the same folder as the htm files to be changed.

Can you provided me with and example of a batch file containing the following in a text file.

Save this script to a file with a BAT extension in the same directory as the exe and the html files, like dochg.bat.  Then to run it just type dochg at a command prompt.

@echo off
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=\"\">" "<table border=\"0\" cellspacing=\"0\" cellpadding=\"5\" width=\"1000\" bgcolor=\"#ffffff\" xmlns:fo=\"\" height=\"87%\">" *.html /s

Open in new window

Note that you need to preface any double quotes in the search and replace strings with a backslash so chgstr doesn't use them as the delimiters for the actual search and replace strings.

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)
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Download and unzip this utility:

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.


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.

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"

thomkat2295Author Commented:
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.
(Free Trial)
Drag all the files into Textpad5.

Click F8
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.

knightEknightConnect With a Mentor Commented:
I don't think there is a way to avoid specifying all 20 search/replace strings.  This utility will traverse the subfolders though, so you can do it all in one batch file like this:

  CD c:\parent

  chgstr.exe  "searchString1"  "replaceString1"  *.html /s
  chgstr.exe  "searchString2"  "replaceString2"  *.html /s
  chgstr.exe  "searchString3"  "replaceString3"  *.html /s
  chgstr.exe  "searchStringN"  "replaceStringN"  *.html /s
... 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
thomkat2295Author Commented:
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="">
"  " <table border="0" cellspacing="0" cellpadding="5" width="1000" bgcolor="#ffffff" xmlns:fo="" 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.
knightEknightConnect With a Mentor Commented:
billprew summed it up very well - the only thing I would add is something that may go without saying, but before running the script, in your command prompt you need to change your current directory to the parent directory containing your .html files, the batch file above, and chgstr.exe.  For example:

  CD  c:\inetpub\wwwroot

Note however that you probably don't want to leave the .bat file or the chgstr.exe file in that folder after the script is done, since it could be exposed.  So after the script is run successfully, move those two files to a different folder.
Why delete this question?
knightEknight, did you read my recommendation?
My bad, the email said it would be deleted - sorry.
thomkat2295Author Commented:
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.
Robert MarleySinger / SongwriterCommented:
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,

Community Support Moderator
All Courses

From novice to tech pro — start learning today.