: Loop # All done /^-*00* /s/// / -*00*$/s/// t # Negative Check /^\(-*\)[0-9].* \1[0-9]/!b Negative # Create magic lookup table s/\(.[0-9]*\) \(.[0-9]*\)/\1;987654321000009999000999009909 \2;012345678999990000999000990090/ s/ \(-\)*\(9*;\)/ \10\2/ # Decrement 1st number s/\([^0]\)\(0*\);[^0]*\1\(.\).*\2\(9*\).* \(.*\)/\3\4 \5/ # Increment 2nd s/\([^9]\)\(9*\);[^9]*\1\(.\).*\2\(0*\).*/\3\4/ t Loop : Negative # Create magic lookup table s/\(.[0-9]*\) \(.[0-9]*\)/\1;987654321000009999000999009909 \2;987654321000009999000999009909/ # Decrement 1st number s/\([^0]\)\(0*\);[^0]*\1\(.\).*\2\(9*\).* \(.*\)/\3\4 \5/ # Decrement 2nd s/\([^0]\)\(0*\);[^0]*\1\(.\).*\2\(9*\).*/\3\4/ t Loop