Saturday, 28 February 2015

Bash rename files based on XML



I am in the process of making a bash script and I need to rename all files of a particular file type (in this case svg) in order to reflect the order in which they are mentioned in an xml file.



<?xml version="1.0" encoding="UTF-8" standalone="yes"?><manifest identifier="id1" version="2006-01" smartnotebook:filesource="SMART Notebook for Mac Version=11.3.804.0" xmlns="http://ift.tt/1i69LaL" xmlns:adlcp="http://ift.tt/1i69Mvh" xmlns:smartnotebook="http://ift.tt/1LUTUrN" xmlns:smartgallery="http://ift.tt/1vIKpb8"><metadata><schema>ADL SCORM</schema><schemaversion>CAM 1.3</schemaversion><adlcp:location>metadata.xml</adlcp:location></metadata><organizations><organization id="pagegroups"><item id="group0" identifierref="group0_pages"><title>Group 1</title></item></organization></organizations><resources><resource identifier="group0_pages" href="page4.svg" type="webcontent" adlcp:scormType="asset"><file href="page4.svg"/><file href="page0.svg"/><file href="page1.svg"/><file href="page3.svg"/><file href="page2.svg"/></resource><resource identifier="pages" href="page4.svg" type="webcontent" adlcp:scormType="asset"><file href="page4.svg"/><file href="page0.svg"/><file href="page1.svg"/><file href="page3.svg"/><file href="page2.svg"/></resource><resource identifier="images"/><resource identifier="sounds"/><resource identifier="attachments"/><resource identifier="flash"/><resource identifier="videos"/><resource identifier="annotationmetadata"/><resource identifier="brush"/></resources></manifest>



I need it to read this file and (for example) rename page4.svg to file0.svg ... and page0.svg to file1.svg. I have been investigating how to do this via xmllint but my xpath knowledge is very limited. Anything is helpfull! thanks!


No comments:

Post a Comment