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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -