File Processing help wanted

R. Hirschfeld yellowdog-general@lists.terrasoftsolutions.com
Wed, 25 Aug 2004 04:26:51 +0200


> Date: Wed, 25 Aug 2004 07:56:48 +0900
> From: David Chart <linux@dchart.demon.co.uk>

> First, I want to replace the contents of every .html file in a hierarchy 
> with a single file. (This file will just contain a link to my new 
> website.) I want to keep all the names intact, so that bookmarks to the 
> depths of the hierarchy will still get the redirect. I'll be doing this 
> to an exported copy of a CVS module, so nothing will be permanently nuked.

This is pretty easy to do, e.g.:

  find top-of-hierarchy -name \*.html -exec ln -f single-file '{}' \;

where top-of-hierarchy is the directory where everything resides and
single-file is the name of the file with which you want to replace
your .html files (by using ln they'll all be the same inode).

But if the structure of the new website is the same as the old one I
think it would be better just to put a single redirect in httpd.conf.
Bookmarks to the depths of the hierarchy on the old site will then be
redirected to the same place on the new site.

> Second, I want to replace all strings of the form '@dchart.demon.co.uk' 
> by '@$mynewdomain.com', in the same hierarchy.

Do you mean strings within the contents of the files?  But you've just
replaced the contents with those of a single file that presumably uses
the desired string.  Or do you mean in the new location?  In that case
you can do something like:

  find top-of-hierarchy -name \*.html -exec perl -pi -e 's/@dchart.demon.co.uk/@$mynewdomain.com/g' '{}' \;

I assume that $mynewdomain stands for something else; if you want a
literal $ in the replacement string you need to precede it with a \.

Hope this helps,
Ray