Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How do I Change Text in a bunch of documents with a script

Posted on 2011-10-03
5
Medium Priority
?
1,707 Views
Last Modified: 2012-05-12
I currently have approx 300 html documents that need to be modified. Rather then opening every one of these in Dreamweaver and manually changing them I had hoped for a script to do this.. I just need to replace the line <td width="18%" nowrap="nowrap" bgcolor="#F0F0F0" class="SubCats">Material:</td>

with
<td width="18%" nowrap="nowrap" bgcolor="#F0F0F0" class="SubCats"><strong>Material:</strong></td>

By putting Strong in the proper area.

Does anyone know of a script that can do this automatically for me.

Thanks

Chip
0
Comment
Question by:CGettler
  • 2
  • 2
5 Comments
 
LVL 25

Expert Comment

by:SStory
ID: 36903175
There are many Unix style tools that can do this:

sed (which is now available on Windows)
http://gnuwin32.sourceforge.net/packages/sed.htm

Another one, for whatever reason is called FART (find and replace text)
http://fart-it.sourceforge.net/
It would probably be the simpler one, but no where near as powerful.
0
 
LVL 25

Accepted Solution

by:
SStory earned 1000 total points
ID: 36903203
Usage of FART.

fart.exe <your folder path>*.html search_text replacement_text

You will have to surround it all by double quotes " ", and for the double quotes used in the HTML you will need to escape them....

so
"<td width= \"18%\"

put \" to tell it  to treat this quote as part of the string.

To tell fart.exe to allow \" you must specify -C option so (here is a partial example)

fart.exe -C <your folder path>*.html "<td width= \"18%\" "<td width=\"20%\""
0
 
LVL 9

Expert Comment

by:jsdray
ID: 36903207
0
 
LVL 5

Assisted Solution

by:magento
magento earned 1000 total points
ID: 36903226
Try this..Tested -its worked for me
for i in `ls`
do
sed 's!<td width="18%" nowrap="nowrap" bgcolor="#F0F0F0" class="SubCats">Material:</td>!<td width="18%" nowrap="nowrap" bgcolor="#F0F0F0" class="SubCats"><strong>Material:</strong></td>!g' $i  > $i.rename
mv $i.rename $i
done

Open in new window

0
 
LVL 5

Expert Comment

by:magento
ID: 36903241
In SSH ,go to path where u have all the codes and paste the above command one by one / or save the code in a file named - rename.sh and run chmod 777 rename.sh .

Run the script as below
./rename.sh
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question