I have an expression of the form @(<date calculation>)
that I want to replace with the result of date +%s --date "now<date calculation>"
. So for example @(-1 day)
would be replaced with the result of date +%s --date "now -1 day"
.
The expression is embedded in a line of text and I can have several. For example echo hi @(-1 day) bye "@(-1 hour)"
. The result of evaluation should be something like echo hi 1491848561 bye "1491931365"
. So I want just the expression to be evaluated, but nothing else.
I tried using GNU's sed 'e' command: sed -r 's|@\(([^)]*)\)|date +%s --date "now\1"|e'
, but this evaluates the entire line, not just the replaced expression.
I'm not attached to using sed, so any other suggestion is welcome, but I'm curious on how to make sed work, for general knowledge