in reply to disappearing digit with regex and tr

I'd say it has something to do with that backspace you're inserting into the string in the first substitution of your map. Don't do that :-)

you can see that the missing 7 is really still there by piping the output of your program through some utility like xxd to get a raw dump.