I am trying to perform a mathematical operation with sed, but it continues to treat my variables as strings. The input is of this kind:
$ echo 12 | sed 's/[0-9]*/&+3/'
$ 12+3
I'd like to have 15 as output. I need to do the operation and replace its mathematical result in only one passage, because I am running the program as a Python daemon, and I want to avoid passages like redirecting stdout on files, open those files, perform operations, extract the result, do the replacement. To me, sed seems the best to perform all in one line.
I've tried to cast both input and output in various ways like
$ echo 12 | sed 's/[0-9]*/int(&+3)/'
$ echo 12 | sed 's/[0-9]*/\int(&+3)/'
$ echo 12 | sed 's/[0-9]*/\int(&+3)/'
but the result was always a printing of the second field.

sedto do math – David Oneill Apr 21 '12 at 13:43