Hello Gary, God bless you.

On Wed, Oct 09, 2002 at 04:19:42PM +0100, Egleton, Gary wrote:
> 
> I have a file with the following repeated several times. The date and time
> will vary.
> 
> UPDATED="06/18/2002 18:42:25"
> 
> I wnat to replace what ver text is between the quotes with NOT APPLICABLE
> 
> ie
>               UPDATED="NOT APPLICABLE"

Assuming you are asking to do that with a CGI script, you can do
something like:

open OLDF, "<file.txt" || die "ERROR";
open NEWF, ">newfile.txt" || die "ERROR";

while(<OLDF>) {
    if ( /UPDATED="(.*?)"/ ) {
        s/$1/NOT APPLICABLE/;
    }
    print NEWF;
}

close OLDF;
close NEWF;

# CAUTION: Investigate and uncomment the following only if right.
#system('rm', 'file.txt'); # assuming no errors!!!
#system('mv', 'newfile.txt', 'file.txt'); # from memory not tested...


Note that on a CGI script you have to be very carefully about where
file.txt and newfile.txt are. I mean, you have to give/have write
access to the appropiate user under which your web server run CGI
scripts.

If you are working from the command line, try:

perl -p -i.old -e 's/$1/NOT APPLICABLE/ if /UPDATED="(.*?)"/' file.txt

This would save your original file.txt as file.txt.old and write the
modified version directly to file.txt

HTH,
Roberto Ruiz.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to