2 added non-sed solution
source | link

If you mix in some bashism:

 echo $(($(echo 12 | sed 's/[0-9]*/&+3/')))

To extract the number from a text:

echo $(($(echo "foo12bar" | sed -r 's/[^0-9]*([0-9]*).*/\1+3/')))

Without sed, just bash:

var="foo12bar"
echo $((${var//[^0-9]/}+3))

replaces every non-digit ${var//[^0-9]/} and does arithmetic in double round parens: $((x+3))

If you mix in some bashism:

 echo $(($(echo 12 | sed 's/[0-9]*/&+3/')))

If you mix in some bashism:

echo $(($(echo 12 | sed 's/[0-9]*/&+3/')))

To extract the number from a text:

echo $(($(echo "foo12bar" | sed -r 's/[^0-9]*([0-9]*).*/\1+3/')))

Without sed, just bash:

var="foo12bar"
echo $((${var//[^0-9]/}+3))

replaces every non-digit ${var//[^0-9]/} and does arithmetic in double round parens: $((x+3))

1
source | link

If you mix in some bashism:

 echo $(($(echo 12 | sed 's/[0-9]*/&+3/')))