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

Re: Excluding files & directories from a glob



zzapper <david@xxxxxxxxxx> wrote:
> The following works just fine
> 
> # grep all coldfusion files except ctpigeon.cfm and env.cfm
> 
> grep -i 'host' **/(*.cfm~(ctpigeonbot|env).cfm)
> 
> But I would like it to also ignore sub-directories named junk*

With extendedglob, the following should work:

  grep -i 'host' **/(*.cfm~(ctpigeonbot|env).cfm)~*((#s)|/)junk*/*(.)

This excludes any pattern which {either starts with junk or contains /junk}
and {contains a / somewhere after the junk}.  Clearly that would only apply
if somewhere in the path there was a subdirectory starting "junk".

I tacked the next bit on at the end just to show the difference, but it's
possibly easier to combine the ~ expressions at the end.  However,
you would need to do the *((#s)|/)(ctpigeonbot|env).cfm trick to make sure
that the name only matched a full directory entry, either in the current
directory or a subdirectory.

You probably don't need the (.) on the end; it just wanted to be there.

Actually, most of my directories contain junk, so I won't be doing that...

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


This message has been scanned for viruses by BlackSpider MailControl - www.blackspider.com



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