I’m parsing a template using linux command line using pipes which has some 1-indexed pseudo-variables, I need 0-indexing. Bascially:
...{1}...{7}...
to become
...{0}...{6}...
I’d like to use one of grep, sed or awk in this order of preference. I guess grep can’t do that but I’m not sure. Is such arithmetic operation even possible using any of these?
- numbers used in the file are in range
0-9, so ignore problems like23becoming12 - no other numbers in the file, so you can even ignore the
{} - I can do that using python, ruby, whatever but I prefer not to so stick to standard command line utils
- other commend line utils usable with pipes with regex that I don’t know are fine too
EDIT: Reworded first bullet point to clarify
If the input allows it, you may be able to get away with simply:
Note that this will replace all instances of any digit, so may not be suitable. (For example,
12becomes01. It’s not clear from the question if you have to deal with 2 digit values.)If you do need to handle multi-digit numbers, you could do: