I'm writing a script in sh to:
- Read a config file
- For each value between
{{ value_0000 }}
retrieve0000
- Perform a command with value
0000
passed as argument - Replace
{{ value_0000 }}
with the output of that command
- Perform a command with value
Notes:
value_0000
always 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
#!/bin/sh
(but I guess that's a typo) and you don't need to cat the file, you can simply dowhile read line; do ...; done < some.conf
– terdon Feb 19 '20 at 15:43{{ value_foo }}
? And what exactly are you expecting as output? Is the objecting just to run the command on each value or do you then want to print out the new key with the new value? And how? To a new file? Do you want to edit the existing file? – terdon Feb 19 '20 at 15:46