I am trying to write a sed command to replace tokens in a file with the values of environment variables, for example:
export my_var=foo
echo 'something {{my_var}} bar' | sed -r "s/\{\{(.*?)\}\}/$\1/g"
In this case, I want to capture the token name ( my_var ), and then replace the value of the environment variable with the same name.
Is it possible? The current text above something $my_var bar
, not the something foo bar
one I want.
I am open to using another tool like awk if this is not possible with sed.
source
share