Search code examples
xmlbashcygwin

Writing bash script to iterate through directories


I have never done any scripting before, so I am completely new to it. I need to run an XSLT translation over multiple files in multiple directories. I am trying to do this on Cygwin.

I currently have a bunch of files (all with the same name, metadata.xml) in different directories. From my current directory, the path is data/Foldername/metadata.xml (with the foldernames being unique).

The pseudocode for this would be:

For all files in /data/Foldername/metadata.xml xsltproc (metadata.xml in current directory) translation.xslt > (output needs to be foldername the current file is in .rdf)


Solution

  • I think this is what you are looking for:

    #!/bin/bash
    files=`find ./ -name 'metadata.xml'`
    for item in $files
    do
      xsltproc $item translation.xslt > ${item%/*}.rdf
    done