Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1995
  • Last Modified:

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
0
thomkat2295
Asked:
thomkat2295
  • 8
  • 3
  • 2
  • +4
3 Solutions
 
omesieCommented:
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.
0
 
omesieCommented:
Sorry, this might help. (or just do a google search)
http://notepad-plus-plus.org/
0
 
knightEknightCommented:
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
0
Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

 
knightEknightCommented:
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]
0
 
selvolCommented:
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"

0
 
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
0
 
selvolCommented:
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
0
 
knightEknightCommented:
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
0
 
knightEknightCommented:
... and if you have more than one filespec, it will take that too:

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

   chgstr.exe  "href=\"Template"  "href=\"suspsyst"  *.html  *.aspx  /s
0
 
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="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.
0
 
Bill PrewCommented:
(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=\"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

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.

~bp
0
 
knightEknightCommented:
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.
0
 
knightEknightCommented:
Why delete this question?
0
 
QlemoC++ DeveloperCommented:
knightEknight, did you read my recommendation?
0
 
knightEknightCommented:
My bad, the email said it would be deleted - sorry.
0
 
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.
0
 
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,

Mod_MarlEE
Community Support Moderator
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 8
  • 3
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now