Search code examples
xmllinuxunixxmlstarlet

How to xmlstarlet on multiple files in different paths?


I am using C Shell.

My working directory:

cd /mnt/FusionOATS/CRM/Research/rys/

My Current Working xmlstarlet command (does an xmlstarlet operation on 2 files which are directly under the working directory and the result is pasted in an output text file):

foreach xmlfile ( ResultReport1.xml ResultReport2.xml )
xmlstarlet sel -t -m '//RESULT_STEP' -v '@time_stamp' -o '|' -v '@step_name' --nl "$xmlfile" >> /scratch/rys/view_storage/outroo3.txt
end

Now I need to this on files which are in different paths like below:

  • Working Directory/ResultReport1.xml

  • Working Directory/ResultReport.xml

  • Working Directory/Test3/ResultReport3.xml

I tried this:

foreach xmlfile ( ResultReport1.xml ResultReport2.xml /Test3/ResultReport3.xml )
xmlstarlet sel -t -m '//RESULT_STEP' -v '@time_stamp' -o '|' -v '@step_name' --nl "$xmlfile" >> /scratch/rys/view_storage/outroo4.txt
end

But, getting the below error:

failed to load external entity "/Test3/ResultReport2.xml"

Can I do this with xmlstarlet? Please suggest. Thanks.


Solution

  • Just removing the slash at the start of the file path resolved the error:

    This worked:

    foreach xmlfile ( ResultReport1.xml ResultReport2.xml Test3/ResultReport2.xml )
    xmlstarlet sel -t -m '//RESULT_STEP' -v '@time_stamp' -o '|' -v '@step_name' --nl "$xmlfile" >> /scratch/rys/view_storage/outroo4.txt
    end