Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: iterating through a hierarchy with a filter
- X-seq: zsh-users 12770
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: iterating through a hierarchy with a filter
- Date: Thu, 10 Apr 2008 09:51:46 +0100
- In-reply-to: <8BAD0AA6-3B6F-4946-B636-6C16B56A944E@xxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <8BAD0AA6-3B6F-4946-B636-6C16B56A944E@xxxxxxxxx>
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
file2=dest/${${file1##source/}:r}.txt
destdir=${file2:h}
[[ -d $destdir ]] || mkdir -p $destdir
filter <$file1 >$file2
done
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