Let's assume we have two directories:
/home/a
/home/b
In directory a with have lots of XML files like this:
<root>
<id>87182378127381273</id>
<name>just a name</name>
</root>
and for each of the id we find an XML file in directory b, like:
/home/b/87182378127381273.xml
...
and in that file we have for instance:
<root>
<counter1>879</counter1>
</root>
And now I just want to run an xmlstarlet command that outputs the following for each found XML in directory a:
87182378127381273,just a name,879
...
I tried to solve this by this xmlstarlet command:
find . -iname '*.xml' | xargs xmlstarlet sel \
-t -m "/root" -i "./id" -v "./id" -o -v "./name" -b -n | grep -v ^$
Now I wanted to use the --var option and load the second XML by constructing the file path with the value of id and output the timestamp value, but I don't know how. Any idea?
Answer rewritten after question was rephrased.
This should do it:
xargswhenfindcan invoke a command with as many filenames ({} +) as the command line can hold and repeat as neededidchild element, no output is generated ifroot[string(id)]isn't matcheddocumentfunction to look up a value in an external XML filedocument()it must be relative to the directory in whichxmlstarletis invoked (i.e. the current directory)xmlstarletwill issue afailed to load external entity "…"error messageconcatfunction to stringify one recordselect's-T(aka--text) option for plaintext output