Change previous row field (substr$0,45,4)-1
Change previous row field (substr$0,72,5)+2
Change actual row field (substr$0,40,4)+1
Change actual row field (substr$0,49,1)-1
Change actual row field (substr$0,62,5)+12
Before
X 4714 14710 69445.00 19257.001 1218 12271 69596.00 19460.00 19478.001
X 4714 14710 69445.00 19257.001 1228 12292 69596.00 19480.00 19480.001
After
X 4714 14710 69445.00 19257.001 1218 12281 69596.00 19460.00 19480.001
X 4714 14710 69445.00 19257.001 1229 12291 69608.00 19480.00 19480.001
Looks like you are overcomplicating things. Why working on characters and substrings? Can't you define it in, say, awk fields? Like if ($7 ~ /2$/) $7+=10 , and so on?
---------- Post updated at 22:03 ---------- Previous update was at 20:08 ----------
Please check if the logics deliver what you need; I took into account your input and output samples, not your verbalized request. You can easily adapt that if need be. Formatting according to your input file will take another exercise and is left to you...
That's much easier; don't need a circular buffer but just set a boolean to remember that "2" was found, modify & print the current line, if boolean set then read, modify, & print the next line ans reset the boolean.