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

Posted on 2011-10-03
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>

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


Question by:CGettler
    LVL 25

    Expert Comment

    There are many Unix style tools that can do this:

    sed (which is now available on Windows)

    Another one, for whatever reason is called FART (find and replace text)
    It would probably be the simpler one, but no where near as powerful.
    LVL 25

    Accepted Solution

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

    "<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%\""
    LVL 9

    Expert Comment

    LVL 5

    Assisted Solution

    Try this..Tested -its worked for me
    for i in `ls`
    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

    Open in new window

    LVL 5

    Expert Comment

    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 - and run chmod 777 .

    Run the script as below

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
    Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
    In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
    HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now