I have an xml that contains paths to 3 other xml files. Let's call the files main, cfg, config and engine. Relavant extract from main.xml:
<cfgfile>path/to/cfg/cfg.xml</cfgfile>
<enginefile>path/to/engine/engine.xml</enginefile>
<configfile>path/to/config/config.xml</configfile>
I want to replace "path/to/x" with pwd (and copy main, cfg, config and engine to pwd). For cfg alone I could do this:
sed 's%path/to/cfg/cfg.xml%"$(pwd)"/cfg.xml' source_path/main.xml > ./main.xml
To make it "simpler" I am trying to this through a loop:
S="";
for ele in "cfg" "engine" "config"; do
S=$S's%<'"$ele"'>.*</'"$ele"'>%<'"$ele"'>'"$(pwd)"'</'"$ele"'>;';
done;
echo $S
I have similar changes in the other 3 files. So, instead of typing out all the commands, loops would be better. I know I could use awk or python more easily, but just trying it out with sed.
So the question is can I use generated variable S as a command in a sed oneliner (without redirecting it to a file) Something like: sed 'use $S' source_path/a.xml