[PLUG] replacing multipule instances of text

Zot O'Connor zot at whiteknighthackers.com
Tue Sep 30 02:08:01 UTC 2003


On Tue, 2003-09-30 at 00:25, alex wrote:
> Hi All,
>         Ive searched high and low but have not been able to find a
> solution to this problem. For the background, I run a photo web
> server(around 600 pages or so and growing) at my home for a track club
> here in the Portland area. They recently acquired their own domain-name
> and I need
> to replace all the homepage links in the HTML with the updated address.
> 
> ex. replace www.foobar.com/RCTC/ with www.RCTC.com/
> 

The devil is in the details, but a quick hack that outlines the issues:

First we must list the files, then edit each file to a temp file, then
move the temp file over the original:

find /path/to/website/files -type f -exec sed -e 's/www.foobar.com\/RCTC\//www.RCTC.com\//g' {} > {}.sed \; -exec mv {}.sed {} \;

find find all files in the path given
  -type f says look at files.
  -exec save exec this until the \;
    {} is the filename being looked at (find subs in)
    sed runs the regex (-e) on the script
       the \ is to protect the / from looking like the end of the regex
       g says do global (i.e. work more than once a line).
     
Having not tried this I bet it fails for any of the following reasons.

I failed to escape the redirection '>'
The {}.sed does not work.
the second exec does not happen.
You have binaries with the expression in them.
You have other things besides links with the regex search pattern.
You have mixed case links.

So make sure you do this on a *copy* first.

For a fairly common thing to do, I have have not seen a common util to
do it.  Often the details cause this approach to work.  I know some web
editors will do this for you.

>         My question is..... is there an easy way to do this other than
> the obvious highlight and pasting of text?

-- 
Zot O'Connor

http://www.ZotConsulting.com
http://www.WhiteKnightHackers.com





More information about the PLUG mailing list