I want to increment every number in quotes in a file, one per line:
perl -pe 's/\"(\d+)\"/ 1 + $1 /ge' file
This strips the quotes, but how do add the quotes back in to the output?
perl -pe 's/\"(\d+)\"/ q{"} . (1 + $1) . q{"} /ge'
You can use look-around assertions - http://perldoc.perl.org/perlre.html#Extended-Patterns.
So the regex becomes: s/(?<=")(\d+)(?=")/ $1 + 1 /ge
And the golf winner is:
perl -pe's/"(\d+)"/"@{[1+$1]}"/g'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With