File Processing help wanted

David Chart yellowdog-general@lists.terrasoftsolutions.com
Fri, 27 Aug 2004 22:30:19 +0900


R. Hirschfeld wrote:

Thanks; this has been a big help.

> 
>>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).
> 

I have to upload the files to the web server afterwards; will it matter 
that they're all linked? Come to that, I guess I could use cp just as 
easily, since I don't have to keep the changed files around.

> 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.
> 

This would be ideal, but I'm not sure I can do it. I don't control the 
web server in question, so I only have access to my home directory. If I 
could do it, what would I have to put in the file, and where would it live?

> 
>>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 \.
> 

I tried this and discovered that @ needs to be escaped as well. Still, 
the syntax worked perfectly, so this saved me a lot of effort. Thanks 
very much for your help!

-- 
David Chart
http://www.davidchart.com/
PGP Key: 1786 15B1 53A3 7ED0 CBD4 AFBE 9B61 6D10 46C9 1CBE