Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: iterating through a hierarchy with a filter

Alexy Khrabrov wrote:
> Greetings -- I have a series of XML files scattered around a  
> hierarchy.  I also have a filter script which reads stdin and writes  
> stdout in a standard Unix way.
> I need to create a mirror hierarchy where files are results of  
> applying the filter to the originals, replacing the original  
> extension, say .xml, with the result extension, say .txt.  Except for  
> the extension change, the hierarchy should be preserved.
> Ideally, my script would not know anything about this whole process,  
> so I can take any filter and use it for my transforms.  The hierarchy  
> for the transformed tree must be created anew so I can easily throw it  
> away (i.e. we do not output the results next to the originals).  The  
> original and result extensions should be provided as a parameter to  
> the process.
> Which zshfoo can I use for it above and beyond find with exec helper  
> script?

zsh doesn't have any specific code for descending hierarchies, so you
would have to do that by trickery.  If it's shallow enough that globbing
the whole thing in one go will work, you can do things along the lines
of (untested):

for file1 in source/**/*.xml; do
  [[ -d $destdir ]] || mkdir -p $destdir
  filter <$file1 >$file2

If that doesn't work even with a few small tweaks, you'll probably have
to tell us why before we can advise better.

Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070

Messages sorted by: Reverse Date, Date, Thread, Author