I'm writing a script in sh to:
- Read a config file
- For each value between
{{ value_0000 }}retrieve0000- Perform a command with value
0000passed as argument - Replace
{{ value_0000 }}with the output of that command
- Perform a command with value
Notes:
value_0000always converts to numbers, e.g.0000- The command is always the same, e.g.
/bin/command <value> - I do not want to edit the current config file, it could just be run in memory
Example:
# this is a config file
key: {{ value_12345 }}:hello
something
another_key: return:{{ value_56789 }}/yeah
./run.sh
# this is a config file
key: returned-value:hello
something
another_key: return:another-returned-value2/yeah
I can retrieve the value from the config file, but requires a lot more code to make it work as desired.
#!/bin/sh
cat some.conf | while read line
do
echo $line
val="$(grep -o -P '(?<={{ value_).*(?= }})')"
command $val
done