J
jrefactors
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");
# read file into an array
@data = <FILE>;
foreach $line (@data)
{ print $line;
$line =~ s/$oldValue/$newValue/
}
Please advise. Thanks!!
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");
# read file into an array
@data = <FILE>;
foreach $line (@data)
{ print $line;
$line =~ s/$oldValue/$newValue/
}
Please advise. Thanks!!