[lug] scripting on linux to replace "find and replace"

Chris Riddoch socket at peakpeak.com
Tue Sep 26 19:38:24 MDT 2000


John Starkey <jstarkey at advancecreations.com> writes:
> 1) I need to create 70 files, all identical except for 2 numbers in the
> <img> tag. These two numbers need to increment relative to the file name
> (file1 -> <img src="001">; file2 -> <img src="002>) ( a slide show ).

Perl: (And yes, there's more than one way to do it)

foreach (1..70)
{
  open(FH, ">data/file$_.html") or die "Couldn't open data/$_.html\n";
  print FH "<img src=\"0" . $_ . ".jpg\">\n";
  close FH;
}

> 2) When the client sends the layout I'll need to break these 70 files down
> into groups and rename both the files and images (140 files at this
> point). I could probably work this without changing the names.

Depends on how it's being broken down, and what the groups are.

> 3) Certain files will need navigation buttons. So I'll need to specify
> which file and where in the file to place these buttons. 
>
> I estimate 4 hours to do all this in HomeSite. I have a feeling this can
> be done in less than an hour in Linux.

Well, if this is all static content, and you know a little Perl, (or
even if you don't, it's still useful without programming knowledge)
I'd plug Website Meta Language.

http://www.engelschall.com/sw/wml/

It's really quite powerful, but if you're up against an immediate
deadline, I'd suggest going with what you know (Homesite is the best
HTML editor I've used besides Emacs, and to avoid the flamewar, yes, I
use vim for things, too) rather than trying to prove something about
Linux.  I can be as rabid as the next guy about using Free Software
and getting it into more places, but in practice, software is just a
tool, you use the right tool for the right job.

On that note, I don't think the shell is particularly the best tool
for tweaking HTML.  It's great if you've already got a collection of
smallish tools for doing the other work you want, and need to run them
in particular ways, but if you're looking for navbar generation, and
building from templates, WML and a dash of Perl is the thing to use,
in my opinion.

--
Chris Riddoch
socket at peakpeak.com




More information about the LUG mailing list