Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

search and replace multiple html files

0 views
Skip to first unread message

brickwall

unread,
Jul 5, 1999, 3:00:00 AM7/5/99
to
Well i've just spent a few hours searching around for info/a script to
help me with a task i have to do. Obviously i had no luck in my
search, so i'm turning to people in here. What i want to do seems
fairly simply, it's to replace a number of lines in html files, with a
new set of lines. The problem i've come across is that there are line
breaks(returns) in the text i want to replace. Every script or search
command i've used doesn't seem to like this.

I'll bet the solution is very simple, but i've no clue what it is. Any
help would be appreciated.

Sample text to replace:

<A HREF="blah.com">
<IMG SRC="blah.gif">
<BR>
That's a picture!


Perhaps a shell script could be used? I'm not sure, tho i tried
playing round with one, no luck there either...

-Hitmyed Gainstde Brickwall

Barry Margolin

unread,
Jul 6, 1999, 3:00:00 AM7/6/99
to
In article <378145af...@news.canadawired.com>,

brickwall <in...@rocketmail.com> wrote:
>Well i've just spent a few hours searching around for info/a script to
>help me with a task i have to do. Obviously i had no luck in my
>search, so i'm turning to people in here. What i want to do seems
>fairly simply, it's to replace a number of lines in html files, with a
>new set of lines. The problem i've come across is that there are line
>breaks(returns) in the text i want to replace. Every script or search
>command i've used doesn't seem to like this.

Perl can be told to read from a file and perform substitions without regard
to line breaks.

--
Barry Margolin, bar...@bbnplanet.com
GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

Ken Pizzini

unread,
Jul 6, 1999, 3:00:00 AM7/6/99
to
On Mon, 05 Jul 1999 23:59:56 GMT, brickwall <in...@rocketmail.com> wrote:
> to replace a number of lines in html files, with a
>new set of lines. The problem i've come across is that there are line
>breaks(returns) in the text i want to replace. Every script or search
>command i've used doesn't seem to like this.

Not directly. With sed, awk, perl (among others) you can effect this
with constructs that they offer, but not with the default behavior.

For example, in sed, if you want to match the lines "foo",
"bar", "baz", and when matched replace them with "ding!":
sed '/^foo$/!b
N
/\nbar$/!{
P
D
}
N
/\nbaz$/!{
P
s/[^\n]*\n//
P
D
}
c\
ding!
'

Or in perl:
perl -pe 'continue if $_ ne "foo\n";
my $n = <>;
if ($n ne "bar\n") {
print $_;
$_ = $n;
redo;
}
my $m = <>;
if ($m ne "baz\n") {
print $_, $n;
$_ = $m;
redo;
}
$_ = "ding!\n";'


--Ken Pizzini

0 new messages