On Mar 10, 2004, at 12:56 PM, Mr Mojo wrote:

Hello,

I have a text file (texst1.txt) that reads:

The quick brown fox jumped over the lazy dog.

I would like to replace the word fox with coyote. Is there an easier/simpler/cooler way to do this?

#!/usr/bin/perl -w
use strict;
open (FILE, "test1.txt");
open (NEWFILE, ">>tmp");
while (<FILE>) {
    if ($_ =~ /fox/) {
        s/fox/coyote/;
    }
    print NEWFILE $_;
}
close FILE;
close NEWFILE;
unlink "test1.txt";
rename "tmp", "test1.txt";

perl -pi -e 's/fox/coyote' text_file_name_here.txt


Is that cool enough? ;)

James


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to