[CS-FSLUG] Script for replacing a string in a html-document?

Frank Bax fbax at sympatico.ca
Wed Oct 5 06:37:45 CDT 2005


At 06:20 AM 10/5/05, Jukka wrote:
>I hope you don't think I am too lazy (which I well may be.. :). I have
>170 similar html-documents with links pointing to a wrong directory
>which I'd like to correct, but not "by hand" (I have done it once
>already and it was tough...). Could someone give me an example-script
>which replaces string in a html-document? I go to look something from
>the net while waiting your responses.


The trickiest part of this exercise is that you want to *update* a file - 
instead of creating new ones.

Here are two scripts (written by friend Doug) we used to update ip 
addresses in zone files.  The zz script identifies the files to be changed, 
then calls zf to actually change them.  Use one or both as you like.  The 
"TIMES" stuff updates current date in zone files - you can skip that 
part.  I don't have time today to clean it up for you.

$ zz oldip newip

$ cat zz
#!/bin/sh
for DD in `grep -l $1 *`
do
./zf $DD $1 $2
done

$ cat zf
#!/usr/bin/perl
die "usage ./zf DOMAIN OLDIP NEWIP" unless ( $ARGV[2] ) ;
$FD=`cat $ARGV[0]`;
@TIMES=localtime(time);
$YEAR=$TIMES[5]+1900;
$MONTH=$TIMES[4]+1;
$DAY=$TIMES[3];
$MONTH='0'.$MONTH if ( $MONTH < 10);
$DAY='0'.$DAY if ( $DAY < 10);
$SERIAL=$YEAR.$MONTH.$DAY.'02';
$FD=~ s/\d\d\d\d\d\d\d\d\d\d/$SERIAL/;
$FD=~ s/$ARGV[1]/$ARGV[2]/g;
print $FD;
#exit 0;
open(OUT,">$ARGV[0]");
print OUT $FD ;
close(OUT);





More information about the Christiansource mailing list