Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: iterating through a hierarchy with a filter
- X-seq: zsh-users 12772
- From: Peter Stephenson <pws@xxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: iterating through a hierarchy with a filter
- Date: Thu, 10 Apr 2008 10:31:10 +0100
- In-reply-to: <DDABD6BC-F3D9-4277-86C1-776B24CB914F@xxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- Organization: CSR
- References: <8BAD0AA6-3B6F-4946-B636-6C16B56A944E@xxxxxxxxx> <200804100851.m3A8pk9S003521@xxxxxxxxxxxxxx> <DDABD6BC-F3D9-4277-86C1-776B24CB914F@xxxxxxxxx>
On Thu, 10 Apr 2008 02:03:21 -0700
Alexy Khrabrov <deliverable@xxxxxxxxx> wrote:
> On Apr 10, 2008, at 1:51 AM, Peter Stephenson wrote:
> >
> > 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.
>
> Well, my hierarchy is a million small files. So I doubt globbing will
> work -- should I try? :)
You might get lucky, but it sounds like you need to do it the hard way.
You can use that code as the core, except you can move the directory
handling out of the way and end up with something like (again this is
untested):
handledir() {
local sdir=$1 ddir=$2
local dir file tail
[[ -d $ddir ]] || mkdir -p $ddir
for dir in $sdir/*(/N); do
handledir $dir $ddir/${dir:t}
done
for file in $sdir/*.xml(N)); do
filter <$file >$ddir/{$file:t}
done
}
handledir sourcedir destdir
The only special zsh features are the globbing flags. (N) forces
the expression to expand to nothing at all if no patterns matched.
--
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