Perl or shell - Get the number from a string variable and increment the number by 1 -
am writing script in shell , i've variable -
$ grep a41a41 file a41a41 06
i want grep particular string combination shown above , increment number associated string (in same line after 2 spaces) 1. , leave rest of file (file have 800 rows). 09 should become 10 , 99 should become 01. also, a41a41 variable , in for loop value of variable change in every iteration doing in loop need consider performance of incrementing.
appreciate in solving problem.
it's unclear should happen 09 - should become 10 or 010?
the former in perl:
perl -i~ -pe 's/(a41a41\s+)([0-9]+)/sprintf "%s%02d", $1, $2 + 1/e' file
to 99 -> 01 transition, use
($2 + 1) % 99 || 99
Comments
Post a Comment