Perl find and replace one liner -


i've been looking @ other find , replace questions on perl, , i'm not sure how implement variation in 1 line. difference want replace 2 things, 1 original, , 1 replacing modification of original string. code have in pm module is:

my $num_args = $#argv + 1; if ($num_args != 2) {     print "\nusage: pscript.pm path file [version]\n";     exit; }  $version = $argv[1]; $revision = $argv[1]; $revision =~ s/.*\.//g; open ($inhandle, "<", $argv[0]) or die $^e; open ($outhandle, ">", "$argv[0].mod") or die $^e; while(my $line = <$inhandle>) {         $line =~ s/\<foo\>(.*)\<\/foo\>/\<foo\>$version\<\/foo\>/;         $line =~ s/\<bar\>(.*)\<\/bar\>/\<bar\>$revision\<\/bar\>/;         print $outhandle $line; }  close $inhandle; close $outhandle;  unlink $argv[0]; rename "$argv[0].mod", $argv[0]; 

what different is:

$revision =~ s/.*\.//g; 

which turns version x.x.x.1000 1000, , uses find , replace.

can done using the

perl -i.bak  -p -e 's/old/new/g;' *.config 

format?

try :

perl -i.bak -pe 's/\d+\.\d+\.\d+\.1000\b/1000/g' *.config 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -