Results 1 to 7 of 7
  1. #1


    Member Since
    Nov 16, 2006
    Location
    Sheffield, UK
    Posts
    96
    Specs:
    MacBook 2.0Ghz Core 2 Duo
    Help Please! Need to do a batch find and replace on a directory full of html files
    Hi

    As per the title really... I need to go through a few hundred html files and get rid of a line out of the header.

    I was going to sit down and do this manually, but I thought I'd rather have a tool do it for me (after all, this is what computers are for, aren't they?)...

    I just need something that can work through a directory full of .htm files and do a find and replace (replacing the line with nothing).

    Any free tools available?

    Anything included in the OS that can do this?

    Your help would be most appreciated

    Thanks in advance!
    Cheers

    Josh (UK)
    Fairly Recent Switcher

  2. #2

    cwa107's Avatar
    Member Since
    Dec 20, 2006
    Location
    Lake Mary, Florida
    Posts
    26,872
    Specs:
    15" MBP, Core i7/2GHz, 8GB RAM, 480GB Crucial M500 SSD
    My suggestion would be to try Automater in your Applications directory (assuming that it works with whatever application you use to edit HTML).

  3. #3


    Member Since
    Mar 11, 2004
    Posts
    1,964
    Apple has at least two pages that might be of help. This one is a step-by-step video of creating an Automator script to batch-change file names.

    This page, without video, explains it, as well.

    If Zoom is turned on in the Universal Access control panel/preferences, you can enlarge the video then shrink it by holding down the Control key and sliding the mouse wheel up and down (or use the keyboard).

    If part of the image enlarges off the screen, drag the mouse from screen edge to screen edge to centre it. You can choose one of the three mouse-dragging actions you might prefer by clicking on the Zoom's Options button. The choices are at the bottom.

  4. #4


    Member Since
    Nov 16, 2006
    Location
    Sheffield, UK
    Posts
    96
    Specs:
    MacBook 2.0Ghz Core 2 Duo
    I ended up getting a guy at work to write me a VB app to do this... he did it in about 15 minutes and it re-wrote over 100 files in 2 seconds

    Shame I had to run it on a PC

    (BTW, it wasn't renaming files, it was finding a line of code within a file, then replacing it with some different text).

    Thanks anyway
    Cheers

    Josh (UK)
    Fairly Recent Switcher

  5. #5

    novicew's Avatar
    Member Since
    Jan 04, 2006
    Location
    Hamburg, Germany
    Posts
    1,385
    Specs:
    MacBook Pro | iMac(2.1 G5) | MacBook(2.16 C2D) | MacMini (1.67 CD) | iPhone 4 | iPad (3rd Gen)
    If you are familiar with the Terminal.App, you need just a single command for that

    1)Open Terminal.App (/Applications/Utilities/Terminal)

    2)cd to the directory where you have all the html files (eg. cd ~/Sites/Mywebsite/)

    3)type find -type f | xargs perl -pi -e 's/<String you want to replace>/<String you want to be replaced with>/g' and hit enter. (eg. find /Users/novicew/newsite/ -type f | xargs perl -pi -e 's/blablabla/blabla/g')

    You can also define the specific file type you want the system to search as follows.
    find /Users/novicew/newsite/ -type f | xargs perl -pi -e 's/blablabla/blabla/g' *.html

    Possibilities are endless, you just need to find them

  6. #6


    Member Since
    Mar 30, 2004
    Location
    USA
    Posts
    4,744
    Specs:
    12" Apple PowerBook G4 (1.5GHz)
    The easy way....

    Open TextWrangler (It's free. Google it. If you're editing HTML, you should have it anyway.)
    Choose Search > Find
    Enter the text you want to search for in the top field
    Enter the replacement text in the second field
    Check the Multi-File Search checkbox at the bottom of the window.
    Click the Other... button. A file-chooser dialog will open.
    Choose the folder that all of these files are in
    Click Replace All
    In the next dialog box, Decide whether you'd like the modified files to be opened (so you can review and save them individually) or saved as soon as the changes are made. Then click Proceed.

    And you're done.

  7. #7


    Member Since
    Nov 16, 2006
    Location
    Sheffield, UK
    Posts
    96
    Specs:
    MacBook 2.0Ghz Core 2 Duo
    Thanks Novicew and Technologist... Both fantastic replies that answer my question.

    Cheers

    Josh (UK)
    Fairly Recent Switcher

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Cant find remote directory using find
    By JeremyRaven in forum OS X - Operating System
    Replies: 3
    Last Post: 10-22-2012, 06:59 PM
  2. Replies: 1
    Last Post: 12-02-2011, 08:39 AM
  3. How to batch find/change html documents
    By Noriker in forum Web Design and Hosting
    Replies: 1
    Last Post: 09-10-2010, 06:36 PM
  4. Opening Local HTML files - render HTML (not display as text)
    By Gator626 in forum OS X - Operating System
    Replies: 6
    Last Post: 11-01-2009, 08:00 PM
  5. Batch Update HTML Files?
    By hadfiiw in forum Web Design and Hosting
    Replies: 2
    Last Post: 01-13-2009, 07:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •