File Processing help wanted

R. Hirschfeld yellowdog-general@lists.terrasoftsolutions.com
Sat, 28 Aug 2004 05:44:56 +0200


> Date: Fri, 27 Aug 2004 22:30:19 +0900
> From: David Chart <ydl@davidchart.com>

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

It shouldn't matter that they're all linked, but they may end up as
separate files on the server after you upload.  Indeed you could use
cp instead of ln -f if you want separate files.

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

Sorry, I assumed that you were running the web server, and further,
that it was apache.  You would need to locate the apache configuration
file httpd.conf on the old server (which could live in any of various
places depending on the OS of the server and/or the whim of its
sysadmin), and add a line of the form:

  Redirect / http://newhost.domain

possibly specifying a path for one or both sides if your site is not
at the top, e.g.:

  Redirect /oldpath http://newhost.domain/newpath

If your (old) host is a virtual host than the redirect line should go
within the container for the virtual host.

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

Sure, glad I could be of help.  Sorry about the @.  BTW, sed might be
more appropriate than perl for the substitution (it's probably more
efficient), but some versions of sed (including the older GNU version
in YDL 3.0.1) don't seem to have an in-place (-i) option.

Ray