EDIT . I donโt know in advance on which โcolumnโ my numbers will be, and I would like to have a single line. Obviously sed does not do arithmetic, so maybe an awk single line solution?
I have a line: (note the interval)
eh oh 37
and I want him to become:
eh oh 36
(so I want to keep the interval)
With awk, I cannot find how to do this as long as I have:
echo "eh oh 37" | awk '$3>=0&&$3<=99 {$3--} {print}'
But it gives:
eh oh 36
(space characters where they are lost because the field separator is equal to '')
Is there a way to ask awk something like "print the output using the same field delimiters as the input?"
Then I tried something else, using the awk sub (.., ..) method:
' sub(/[0-9][0-9]/, ...) {print}'
but there is no cigar yet: I do not know how to refer to regexp and do arithmetic on it in the second argument (which I left with "...").
Then I tried with sed, but got stuck after that:
echo "eh oh 37" | sed -e 's/\([0-9][0-9]\)/.../'
Can I do arithmetic from sed using the link to the corresponding numbers, and so that the output does not change the number of space characters?
Please note that this is related to my question regarding Emacs and how to apply it to some (large) Emacs region (using the replacement area using the Emacs-on-region shell-shell), but this is not an identical question: this one is about how " keep spaces "when working with awk / sed / etc.