Welcome to WebmasterWorld Guest from 50.17.87.126

Forum Moderators: open

Message Too Old, No Replies

How to edit a bunch of static HTML files at once?

     

Perfection

1:21 am on Oct 20, 2008 (gmt 0)

10+ Year Member



I have an older site that is just about 100 static html pages. Instead of hand editing 100 files, what I'd like to do is make the same edits to all of them, all at once.

I use Notepad++, which kind of does this with the "Find" and "Replace All" functions, but this only works with a small number of characters. I want to basically replace a block of code with another block of code... or just add a block of code to a specific spot without replacing anything.

Does anyone know if there is any way to do this or any program that will give me this capability?

Thanks in advance for any help.

bill

2:57 am on Oct 20, 2008 (gmt 0)

WebmasterWorld Administrator bill is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month Best Post Of The Month



UltraEdit, FrontPage, and Expression Web all seem to have this ability and have worked for me. I didn't know that Notepad++ was so limited.

Lexur

6:51 am on Oct 20, 2008 (gmt 0)

5+ Year Member



Search and replace 98.

It's a small program to replace blocks of code (breaks included) in the files of a directory and its subdirectories.

Perfection

5:07 pm on Oct 20, 2008 (gmt 0)

10+ Year Member



Awesome, thanks guys!

dreamcatcher

6:10 pm on Oct 22, 2008 (gmt 0)

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member



PSPad has a plugin for multi line find and replace.

dc

vincevincevince

4:42 am on Nov 16, 2008 (gmt 0)

WebmasterWorld Senior Member vincevincevince is a WebmasterWorld Top Contributor of All Time 10+ Year Member



cat 'file' ¦ sed "s/from/to/g" > newfile

willis1480

4:34 pm on Nov 17, 2008 (gmt 0)

10+ Year Member



just chmod all files to 777.
create phpFix.php file
 
//use scandir to get all files, PHP 5+
foreach(scandir($mydiroffiles) as $value){
//dont look at .. and . in directory, linux and windows
if($value !== "." && $value !== ".."){
//create handle for opening file for writing
$handle = fopen($value,"w");
//get content of file into string
$fileContent = fread($handle,filesize($value));
//replace using regular expression
$fileContent = preg_replace($regex,$replacewith,$fileContent);
//write new contents to file
fwrite($value,$fileContent);
//close handle
fclose($handle);
}
//cycle back through for each file
}

totally untested, but you should get the idea. Make sure you get the regular expression right, otherwise you may cause some problems for yourself. A backup would be a great idea.

good luck

gibbs_h

6:30 am on Dec 17, 2008 (gmt 0)

5+ Year Member



if you are using Dreamweaver then you can easily replace multiple line code for every page.. just search and replace.....

caine

1:42 am on Dec 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



try 'Multiple File Search & Replace' - can do alot of pages at once - it will do exactly what you asking - windows friendly.

Quadrille

1:58 am on Dec 25, 2008 (gmt 0)

WebmasterWorld Senior Member quadrille is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Much easier to use SSI, if it's stuff you know in advance that you'll be changing; such as navigation, advertisement code ...

You can do that in notepad without any extra programming required.

SteveWh

3:17 am on Dec 25, 2008 (gmt 0)

5+ Year Member



FrontPage (and almost certainly Expression Web) has a good regex search and replace.

Another, nonobvious, candidate is Microsoft Visual C++ Express (free). It's a programming environment, but its search and replace (including regex and multi-file searching) is very good.

[edited by: SteveWh at 3:18 am (utc) on Dec. 25, 2008]

g1smd

4:03 pm on Dec 25, 2008 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



See also EditPlus3, TextEdit3, and others.

CWI Tech Guy

9:56 am on Jan 7, 2009 (gmt 0)

5+ Year Member



This is a good thread, i've come across similar problems in the past that were resolved with a perl script of unknown origin. I'll definitely bookmark this one.

willis1480

3:01 pm on Jan 7, 2009 (gmt 0)

10+ Year Member



Ok...I have been using dreamweaver for awhile, but it always drove me nuts that it wasnt well suited for backend programing.

In my search of PHP IDE, I have come across Eclipse for PHP. This has a file find and replace, by exact phrase or regex. In addition you can choose what folders for it to search.

In addition, it is simply the best editor/programming tool I have used thus far. Did I mention it is FREE!

comes with code hints, SVN, pluggin for any programming language. The best search function. I have been only using if for about a month now. Just been unwilling to pay zen, phpIDE, etc...

I recommend everyone try it. Not a WYSIWYG though.

coopster

3:09 pm on Jan 7, 2009 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I use Eclipse exclusively and the latest release (last fall) updated the regular expression search/replace feature and is even better than earlier releases. It's like having the power of unix command line search/replace utilities inside of your project manager.

Laisha

10:04 pm on Jan 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Pica or Arachnophilia, IMHO.

CrustyAdmin

9:49 pm on Mar 3, 2009 (gmt 0)

5+ Year Member



you may have already finished this task, but if you haven't or anyone else needs to do something similar. BK Replacem is a great utility

grelmar

9:36 am on Mar 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's for stuff like this that I still keep a copy of Homesite installed (first it was Allaire Homesite, then Macromedia Homesite, then Adobe bough Macromedia, and it vanished). Outdated, deprecated, bought out by progressively fatter software companies until it got relegated into not-quite-abandonware (ie: you can't buy it, but lord help you if you in any way violate the copyright). So don't go searching in the darker parts of the net for it, because that would be wrong >:-}

And still, hands down, the best HTML code editing software ever.

Mass search and replace:
All open files (organized in tabs, years before tabs were cool).
All files in a directory.
All files in a group of directories.

For old "code junkies" who never cottoned on to WYSIWIG design tools that generate their own (bloated) code, it still reigns supreme. (IMHO)

Failing that, learn Bash Scripting [tldp.org]. Specifically how to use grep [ss64.com] to pull and swap text between files.

Teaching yourself Bash might seem excessive for one little project, but it's time well spent in the long run if you ever plan on running your own servers.

robzilla

10:03 am on Mar 21, 2009 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month



I like Actual Search & Replace. Its name says enough about many other search and replace programs that you just can't rely on. This one hasn't failed me yet and allows you to replace entire blocks of code. You don't have to manually create lists of files it needs to search through, just feed it a directory and a list of file extensions (or *.*).

dreamcatcher

11:55 am on Mar 21, 2009 (gmt 0)

WebmasterWorld Senior Member dreamcatcher is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Alias Search & Replace is also excellent. Thats what I used years ago when I did static html sites. A really useful right click utility is b4Text. Right click any folder and run a multi line search & replace. Besides the PSPad multi line search and replace option, thats pretty much what I use.

dc

Receptional Andy

12:07 pm on Mar 21, 2009 (gmt 0)



I second BK ReplaceEm (on Windows) - fast and straightforward to use.

arikgub

1:05 pm on Mar 21, 2009 (gmt 0)

10+ Year Member



Nothing can be done as quickly as the proposed

cat 'file' sed "s/from/to/g" > newfile

which is equivalent to

sed -i "s/from/to/g" file

and when applied to multiple files at once takes the form

find . -exec "sed -i s/from/to/g {} \;"

Angonasec

1:50 pm on Mar 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And... The rest of us use TextWrangler. Powerful and free.

swa66

2:17 pm on Mar 21, 2009 (gmt 0)

WebmasterWorld Senior Member swa66 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



If you create xhtml (which is essentially xml), and it is well structured (it should be - really!), then you can edit your xhtml files as if they are xml: you've far more powerful means of selecting parts of the document than even a very elaborate regexp can do.

Let's say you have a wish to add a class="green" on all <a> tags that are inside a <p> that has an attribute class="widget", but no id.

Good luck to do it if you can't parse the tree semantically.

MatthewHSE

2:52 pm on Mar 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



EditPadPlus works great for find-replace stuff. It also has handy features like "Open Folder" and "Save All" that make it great for handling large numbers of files at once. Very fast and light too.

And yes, SSI or PHP includes are the way to go for as many page elements as possible other than the main content.

swa66, that sounds incredibly cool. Assuming well-structured xhtml, what would you use to do the kind of editing you're talking about?

signor_john

3:15 pm on Mar 21, 2009 (gmt 0)



HomeSite also has a great search-and-replace function. (I use FrontPage and Expression Web for most things, but when I want to replace a block of text on a large number of files, I drag out my ancient version of HomeSite, which came free with another application years ago. I also find it convenient for editing .htaccess and RSS files.)

johnnie

3:23 pm on Mar 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



TextPad has a muli-file search-and-replace.

explorador

3:47 pm on Mar 21, 2009 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



EditPadPlus works great for find-replace stuff. It also has handy features like "Open Folder" and "Save All" that make it great for handling large numbers of files at once. Very fast and light too.

EditPad is great, I use it and like it for its speed and simplicity. Also little memory consumption. The problem is when the same code changes from page to page, ej: a little extra space, numbers, etc. Then you have to use the functions again and again to tweak it.

BBedit (Mac) has wild card features, allowing you to search and replace text even if it has some different characters, you can use # for numbers, you can use * and such.

nealrodriguez

4:56 pm on Mar 21, 2009 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



this thread is great for anybody working with enterprise sites with thousands maybe millions of pages. especially if you want to add a canonical tag to 30 duplicates - yes, i know that's bad; but i have seen it; or i could see it if you want to enter a call of an abstract to dynamically populate descriptions or h1's.

dibbern2

4:59 pm on Mar 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Another vote for HomeSite. And for really large block replacement, NotePro. Incredibly fast.
This 66 message thread spans 3 pages: 66
 

Featured Threads

Hot Threads This Week

Hot Threads This Month