New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Operating System General OS operation information and support

OS 10.4 - Help Please! Need to do a batch find and replace on a directory full of html files


Post Reply New Thread Subscribe

 
Thread Tools
MrJoshua

 
Member Since: Nov 16, 2006
Location: Sheffield, UK
Posts: 97
MrJoshua has a spectacular aura about
Mac Specs: MacBook 2.0Ghz Core 2 Duo

MrJoshua is offline
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
QUOTE Thanks
cwa107

 
cwa107's Avatar
 
Member Since: Dec 20, 2006
Location: Middletown, Pennsylvania
Posts: 26,493
cwa107 has a reputation beyond reputecwa107 has a reputation beyond reputecwa107 has a reputation beyond reputecwa107 has a reputation beyond reputecwa107 has a reputation beyond reputecwa107 has a reputation beyond reputecwa107 has a reputation beyond reputecwa107 has a reputation beyond reputecwa107 has a reputation beyond reputecwa107 has a reputation beyond reputecwa107 has a reputation beyond repute
Mac Specs: 15" MBP, Core i7/2GHz, 8GB RAM, 480GB Crucial M500 SSD

cwa107 is offline
My suggestion would be to try Automater in your Applications directory (assuming that it works with whatever application you use to edit HTML).
QUOTE Thanks
Brown Study

 
Brown Study's Avatar
 
Member Since: Mar 11, 2004
Location: Winnipeg
Posts: 1,964
Brown Study is a name known to allBrown Study is a name known to allBrown Study is a name known to allBrown Study is a name known to allBrown Study is a name known to allBrown Study is a name known to allBrown Study is a name known to all
Mac Specs: G4 Tiger and OS 9

Brown Study is offline
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.
QUOTE Thanks
MrJoshua

 
Member Since: Nov 16, 2006
Location: Sheffield, UK
Posts: 97
MrJoshua has a spectacular aura about
Mac Specs: MacBook 2.0Ghz Core 2 Duo

MrJoshua is offline
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
QUOTE Thanks
novicew

 
novicew's Avatar
 
Member Since: Jan 04, 2006
Location: Hamburg, Germany
Posts: 1,385
novicew is a name known to allnovicew is a name known to allnovicew is a name known to allnovicew is a name known to allnovicew is a name known to allnovicew is a name known to allnovicew is a name known to all
Mac Specs: MacBook Pro | iMac(2.1 G5) | MacBook(2.16 C2D) | MacMini (1.67 CD) | iPhone 4 | iPad (3rd Gen)

novicew is offline
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
QUOTE Thanks
technologist

 
Member Since: Mar 30, 2004
Location: USA
Posts: 4,744
technologist has a reputation beyond reputetechnologist has a reputation beyond reputetechnologist has a reputation beyond reputetechnologist has a reputation beyond reputetechnologist has a reputation beyond reputetechnologist has a reputation beyond reputetechnologist has a reputation beyond reputetechnologist has a reputation beyond reputetechnologist has a reputation beyond reputetechnologist has a reputation beyond reputetechnologist has a reputation beyond repute
Mac Specs: 12" Apple PowerBook G4 (1.5GHz)

technologist is offline
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.
QUOTE Thanks
MrJoshua

 
Member Since: Nov 16, 2006
Location: Sheffield, UK
Posts: 97
MrJoshua has a spectacular aura about
Mac Specs: MacBook 2.0Ghz Core 2 Duo

MrJoshua is offline
Thanks Novicew and Technologist... Both fantastic replies that answer my question.


Cheers

Josh (UK)
Fairly Recent Switcher
QUOTE Thanks

Post Reply New Thread Subscribe


« Newb question regarding dock | Kernel Panic »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

All times are GMT -4. The time now is 09:36 AM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?