Thursday, 16 May 2013

find and replace using perl script

USAGE: perl "scriptname" "word to find" "word to replace" "file to which you are going to perform the  action"

$find=$ARGV[0];
$replace=$ARGV[1];
$file=  $ARGV[2];
open(FILE,"$file");
while($line=<FILE>)
{
if($line=~/bash/)
{
$line=~s/$find/$replace/;
print $line."\n";
}
else
{
print $line."\n";
}
}
close(FILE);

No comments:

Post a Comment