I need to read some filenames from an xml config file using xmlstarlet with an .sh script and merge contents of these files (in same order) into a single file.
Here is my xml structure:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<level1>
...
</level1>
<level2>
<david>
<txtfile>file1.txt</txtfile>
<txtfile>file2.txt</txtfile>
<txtfile>somefile.txt</txtfile>
<incfile>config.inc</incfile>
<incfile>foo.inc</incfile>
</david>
<jack>
<txtfile>filex.txt</txtfile>
<txtfile>filey.txt</txtfile>
<incfile>otherconfig.inc</incfile>
<incfile>foo1.inc</incfile>
</jack>
</level2>
</config>
After reading (maybe adding to an array in bash) these filenames using xmlstarlet i have to merge file contents into a single file using a command like
cat file1.txt,file2.txt,filex.txt > jack.txt
but i’m not sure. I don’t have good skills in .sh scripting but in summary, i need to generate some merged files which including contents of above filenames like this:
/level2/david.txt (includes file1.txt, file2.txt, somefile.txt )
/level2/david.inc (includes config.inc, foo.inc)
/level2/jack.txt (includes filex.txt, filey.txt)
/level2/jack.inc (includes otherconfig.inc, foo1.inc)
How can i do that?
1 Answer