On Fri, 2008-09-19 at 20:53 -0700, [EMAIL PROTECTED] wrote:
> Here's a string in my file,
> 
> #define MY2D_STRING            "4.0.1.999.9"
> 
> of which I'm trying to increment the last digit; let's say with 1,
> 
> such that the output is 4.0.1.999.10
> 
> I've tried _various_ combinations, here's just one of them.
> (This works partially, but not always).
> 
> perl -i -pe 'if (/(MY2D_STRING\b.*)(.\d+)"/){$a=$2;s/$a/$a+1/ge}'
> $filename
> 
> ------------
> Also, another one (though I can figure this out with help with just
> the first one)
> 
> MY3D_STRING(test, 4.0.1.999.9)
> 
> 
> TIA.
> 
> 

This will increment the last number in a dotted number:

perl -ple 's/([\d.]+\.)(\d+)/$1.(++($n=$2))/eg'


-- 
Just my 0.00000002 million dollars worth,
  Shawn

"Where there's duct tape, there's hope."
        Cross Time Cafe

"Perl is the duct tape of the Internet."
        Hassan Schroeder, Sun's first webmaster

"There is more than one way to do things."
        A Perl axiom


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


Reply via email to