Nawa
Nawa

Reputation: 2158

Copy non xml resources

I need to process xml file and copy some resources that occur in it

Input resources

-inputFolder
  -1.xml
  -1.jpg
  -2.jpg

Content of 1.xml:

<links>
   <link ref="1.jpg"/>
   <link ref="2.jpg"/>
</links>

Output resources

-outputFolder
  -1.xml.out
  -1.jpg
  -2.jpg

Content of 1.xml.out:

<links_new>
  <link_new ref_new="1.jpg"/>
  <link_new ref_new="2.jpg"/>
</links_new>

Thus I want to copy 1.jpg and 2.jpg, Is it possible?

Upvotes: 0

Views: 143

Answers (1)

Oleg Pavliv
Oleg Pavliv

Reputation: 21192

You can use XML starlet command tool to parse xml files.

To copy 1.jpg and 2.jpg use the following command (works on unix or cygwin):

xml sel -t -m "/links/link/@ref" -v '.' -o ';' 1.xml | xargs -d';' -I {} cp /input/path/{} /output/path/

The command

xml sel -t -m "/links/link/@ref" -v '.' -o ';' 1.xml

selects all jpg files and separates them by ';'.

Then xargs parses the input and pass it to cp which copies files to the destination directory.

Upvotes: 1

Related Questions