zsh-users
 help / color / mirror / code / Atom feed
* Excluding files & directories from a glob
@ 2005-10-04 15:53 zzapper
  2005-10-04 16:14 ` Peter Stephenson
  0 siblings, 1 reply; 10+ messages in thread
From: zzapper @ 2005-10-04 15:53 UTC (permalink / raw)
  To: zsh-users

Hi Zeddites

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*


How do?



-- 
zzapper
Success for Techies and Vim,Zsh tips
http://SuccessTheory.com/


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Excluding files & directories from a glob
  2005-10-04 15:53 Excluding files & directories from a glob zzapper
@ 2005-10-04 16:14 ` Peter Stephenson
  2005-10-04 18:25   ` zzapper
  2005-10-14 18:43   ` Hannu Koivisto
  0 siblings, 2 replies; 10+ messages in thread
From: Peter Stephenson @ 2005-10-04 16:14 UTC (permalink / raw)
  To: zzapper; +Cc: zsh-users

zzapper <david@tvis.co.uk> 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@csr.com>                  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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Excluding files & directories from a glob
  2005-10-04 16:14 ` Peter Stephenson
@ 2005-10-04 18:25   ` zzapper
  2005-10-05  3:01     ` Jean Chalard
  2005-10-14 18:43   ` Hannu Koivisto
  1 sibling, 1 reply; 10+ messages in thread
From: zzapper @ 2005-10-04 18:25 UTC (permalink / raw)
  To: zsh-users

On Tue, 4 Oct 2005 17:14:38 +0100,  wrote:

>zzapper <david@tvis.co.uk> 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*/*(.)
>
Is the following OK/ (appears 2b?)

grep -i 'host' **/(*.cfm~ctpigeonbot.cfm)~junk*/*


-- 
zzapper
Success for Techies and Vim,Zsh tips
http://SuccessTheory.com/


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Excluding files & directories from a glob
  2005-10-04 18:25   ` zzapper
@ 2005-10-05  3:01     ` Jean Chalard
  2005-10-06  8:59       ` zzapper
  0 siblings, 1 reply; 10+ messages in thread
From: Jean Chalard @ 2005-10-05  3:01 UTC (permalink / raw)
  To: zzapper; +Cc: zsh-users

> >  grep -i 'host' **/(*.cfm~(ctpigeonbot|env).cfm)~*((#s)|/)junk*/*(.)
>
> Is the following OK/ (appears 2b?)
>
> grep -i 'host' **/(*.cfm~ctpigeonbot.cfm)~junk*/*

The difference between what Peter posted and this is that this pattern
will only avoid files with a path starting with 'junk' relative to the
current directory.
To make it more concrete, it behaves the same except in the case when
you have a subdirectory called junk not immediately in the directory
you're executing the command in, so any file under a directory
./*/junk*/ would not be ignored.
For example, if you have
./foo
./junkfoo/bar
./qux/junkcorge/garply

Then your pattern will match the third file whereas Peter's one will exclude it.

--
J
"If you wish to leave a record of your call,
 please state your messij at the sound of the tone."

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Excluding files & directories from a glob
  2005-10-05  3:01     ` Jean Chalard
@ 2005-10-06  8:59       ` zzapper
  2005-10-06  9:10         ` Jean Chalard
  0 siblings, 1 reply; 10+ messages in thread
From: zzapper @ 2005-10-06  8:59 UTC (permalink / raw)
  To: zsh-users

On Wed, 5 Oct 2005 12:01:46 +0900,  wrote:

>> >  grep -i 'host' **/(*.cfm~(ctpigeonbot|env).cfm)~*((#s)|/)junk*/*(.)
>>
Ok I give in what does the qualifier #s mean and do, and where is it in the doc.

Thanks

-- 
zzapper
Success for Techies and Vim,Zsh tips
http://SuccessTheory.com/


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Excluding files & directories from a glob
  2005-10-06  8:59       ` zzapper
@ 2005-10-06  9:10         ` Jean Chalard
  2005-10-06 10:23           ` zzapper
  0 siblings, 1 reply; 10+ messages in thread
From: Jean Chalard @ 2005-10-06  9:10 UTC (permalink / raw)
  To: zzapper; +Cc: zsh-users

> >> >  grep -i 'host' **/(*.cfm~(ctpigeonbot|env).cfm)~*((#s)|/)junk*/*(.)
>
> Ok I give in what does the qualifier #s mean and do, and where is it in the doc.

The #s qualifier matches the start of a string. In the manual you can find its
description on the "13.8 Filename generation" section, under 13.8.4 :
globbing flags.
Here is the relevant chunk of documentation :

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
s, e
     Unlike the other flags, these have only a local effect, and each
     must appear on its own:  `(#s)' and `(#e)' are the only valid
     forms.  The `(#s)' flag succeeds only at the start of the test
     string, and the `(#e)' flag succeeds only at the end of the test
     string; they correspond to `^' and `$' in standard regular
     expressions.  They are useful for matching path segments in
     patterns other than those in filename generation (where path
     segments are in any case treated separately).  For example,
     `*((#s)|/)test((#e)|/)*' matches a path segment `test' in any of
     the following strings: test, test/at/start, at/end/test,
     in/test/middle.

     Another use is in parameter substitution; for example
     `${array/(#s)A*Z(#e)}' will remove only elements of an array which
     match the complete pattern `A*Z'.  There are other ways of
     performing many operations of this type, however the combination
     of the substitution operations `/' and `//' with the `(#s)' and
     `(#e)' flags provides a single simple and memorable method.

     Note that assertions of the form `(^(#s))' also work, i.e. match
     anywhere except at the start of the string, although this actually
     means `anything except a zero-length portion at the start of the
     string'; you need to use `(""~(#s))' to match a zero-length
     portion of the string not at the start.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

--
J
"If you wish to leave a record of your call,
 please state your messij at the sound of the tone."

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Excluding files & directories from a glob
  2005-10-06  9:10         ` Jean Chalard
@ 2005-10-06 10:23           ` zzapper
  2005-10-06 10:52             ` Jean Chalard
  0 siblings, 1 reply; 10+ messages in thread
From: zzapper @ 2005-10-06 10:23 UTC (permalink / raw)
  To: zsh-users

On Thu, 6 Oct 2005 18:10:53 +0900,  wrote:

>> >> >  grep -i 'host' **/(*.cfm~(ctpigeonbot|env).cfm)~*((#s)|/)junk*/*(.)
>>
>> Ok I give in what does the qualifier #s mean and do, and where is it in the doc.
>
>The #s qualifier matches the start of a string. In the manual you can find its
>description on the "13.8 Filename generation" section, under 13.8.4 :
>globbing flags.
>Here is the relevant chunk of documentation :
Thanx Jean
Now I understand the above.

However the following (simplified example) still seems to work:-

list all files fred unless they are in a subdirectory *junk*

ls **/fred~*junk*/*

-- 
zzapper
Success for Techies and Vim,Zsh tips
http://SuccessTheory.com/


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Excluding files & directories from a glob
  2005-10-06 10:23           ` zzapper
@ 2005-10-06 10:52             ` Jean Chalard
  2005-10-06 16:23               ` zzapper
  0 siblings, 1 reply; 10+ messages in thread
From: Jean Chalard @ 2005-10-06 10:52 UTC (permalink / raw)
  To: zzapper; +Cc: zsh-users

> >> >> >  grep -i 'host' **/(*.cfm~(ctpigeonbot|env).cfm)~*((#s)|/)junk*/*(.)
> >>
> >> Ok I give in what does the qualifier #s mean and do, and where is it in the doc.
> >
> >The #s qualifier matches the start of a string. In the manual you can find its
> >description on the "13.8 Filename generation" section, under 13.8.4 :
> >globbing flags.
> >Here is the relevant chunk of documentation :
> Thanx Jean
> Now I understand the above.
>
> However the following (simplified example) still seems to work:-
>
> list all files fred unless they are in a subdirectory *junk*
>
> ls **/fred~*junk*/*

Of course it does ! It's just *less* restrictive than the pattern Peter wrote.
If you have a subdirectory named not_junk, this pattern will skip all
its contents,
whereas Peter's pattern will include it.

--
J
"If you wish to leave a record of your call,
 please state your messij at the sound of the tone."

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Excluding files & directories from a glob
  2005-10-06 10:52             ` Jean Chalard
@ 2005-10-06 16:23               ` zzapper
  0 siblings, 0 replies; 10+ messages in thread
From: zzapper @ 2005-10-06 16:23 UTC (permalink / raw)
  To: zsh-users

On Thu, 6 Oct 2005 19:52:21 +0900,  wrote:

>> >> >> >  grep -i 'host' **/(*.cfm~(ctpigeonbot|env).cfm)~*((#s)|/)junk*/*(.)
>> >>
>> >> Ok I give in what does the qualifier #s mean and do, and where is it in the doc.
>> >
>> >The #s qualifier matches the start of a string. In the manual you can find its
>> >description on the "13.8 Filename generation" section, under 13.8.4 :
>> >globbing flags.
>> >Here is the relevant chunk of documentation :
>> Thanx Jean
>> Now I understand the above.
>>
>> However the following (simplified example) still seems to work:-
>>
>> list all files fred unless they are in a subdirectory *junk*
>>
>> ls **/fred~*junk*/*
>
>Of course it does ! It's just *less* restrictive than the pattern Peter wrote.
>If you have a subdirectory named not_junk, this pattern will skip all
>its contents,
>whereas Peter's pattern will include it.
Aaah!!

-- 
zzapper
Success for Techies and Vim,Zsh tips
http://SuccessTheory.com/


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Excluding files & directories from a glob
  2005-10-04 16:14 ` Peter Stephenson
  2005-10-04 18:25   ` zzapper
@ 2005-10-14 18:43   ` Hannu Koivisto
  1 sibling, 0 replies; 10+ messages in thread
From: Hannu Koivisto @ 2005-10-14 18:43 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zzapper, zsh-users

Peter Stephenson <pws@csr.com> writes:

> zzapper <david@tvis.co.uk> wrote:
...
>> 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*/*(.)

Wouldn't this

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

be a simpler way?

-- 
Hannu


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2005-10-14 18:44 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-04 15:53 Excluding files & directories from a glob zzapper
2005-10-04 16:14 ` Peter Stephenson
2005-10-04 18:25   ` zzapper
2005-10-05  3:01     ` Jean Chalard
2005-10-06  8:59       ` zzapper
2005-10-06  9:10         ` Jean Chalard
2005-10-06 10:23           ` zzapper
2005-10-06 10:52             ` Jean Chalard
2005-10-06 16:23               ` zzapper
2005-10-14 18:43   ` Hannu Koivisto

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).