search/replace and update the file in perl script

search/replace and update the file in perl script

Post by jrefact.. » Sat, 18 Dec 2004 11:00:07



I need a perl script to search and replace the keywords in a file, and
update that file with new
keyword.

The usage should be perl modify.pl oldvalue newvalue filename

I wrote the script, I can search and replace, but I guess
the problem is I don't know how to update the file.

#!/usr/bin/perl
$oldValue = $ARGV[0];
$newValue = $ARGV[1];
$fileName = $ARGV[2];

open(FILE, $fileName) or die("Unable to open file");



{ print $line;
$line =~ s/$oldValue/$newValue/

Quote:}

Please advise. Thanks!!
 
 
 

search/replace and update the file in perl script

Post by jrefact.. » Sat, 18 Dec 2004 11:19:59


I need a perl script to search and replace the keywords in a file, and
update that file with new
keyword.

The usage should be perl modify.pl oldvalue newvalue filename

I wrote the script, I can search and replace, but I guess
the problem is I don't know how to update the file.

#!/usr/bin/perl
$oldValue = $ARGV[0];
$newValue = $ARGV[1];
$fileName = $ARGV[2];

open(FILE, $fileName) or die("Unable to open file");



{ print $line;
$line =~ s/$oldValue/$newValue/

Quote:}

Please advise. Thanks!!

 
 
 

search/replace and update the file in perl script

Post by Jürgen Exne » Sat, 18 Dec 2004 11:45:31



> I need a perl script to search and replace the keywords in a file, and
> update that file with new
> keyword.

> The usage should be perl modify.pl oldvalue newvalue filename

> I wrote the script, I can search and replace, but I guess
> the problem is I don't know how to update the file.
[...]
> Please advise. Thanks!!

Please see
    perldoc -q "change one line"

jue