Re: Sed: replacing text with textfile content

From: Juergen Heck (btd.heck_at_t-online.de)
Date: 08/21/03


Date: Thu, 21 Aug 2003 16:42:56 +0200


Ek Strensom wrote:
>
> Can I use sed to replace a string of text in one file, with the
> entire contents of another file? I keep on running into
> problems with special characters....even when I use characters
> that don't occur in the HTML. :-(
>
> cat "${TEMPLATE}" | \
> sed "s@<!--#include VIRTUAL=\"ssi/css\"-->@`cat ~/public_html/ssi/css`@g" > \
> "${OUTFILE}"
>
> In this case, I want to replace the following text in the
> template:
>
> <!--#include VIRTUAL="ssi/css"-->
>
> With the entire contents of ~/public_html/ssi/css, before
> writing the output to a separate file.
>
> (Why I'm doing this with SSI is a long story. Most of my site
> features can use the SSI, except for a single page hosted by an
> outside site for CGI reasons. It would be easier to update the
> template like this when SSI specific code is updated (rarely).)
> --
> Ek Strensom
Untested

sed '/<!--#include VIRTUAL="ssi\/css"-->/'"d;r
$HOME/public_html/ssi/css" $TEMPLATE

Regards
Juergen