zsh-users
 help / color / mirror / code / Atom feed
* avoid file not found error with { .. } expansion
@ 2003-12-01 11:17 Eric Smith
  2003-12-01 12:02 ` Peter Stephenson
  2003-12-01 12:07 ` avoid file not found error with { .. } expansion Thomas Köhler
  0 siblings, 2 replies; 7+ messages in thread
From: Eric Smith @ 2003-12-01 11:17 UTC (permalink / raw)
  To: Zsh Users

What would be the correct invocation for this:

$ xview {02..19}.*jpg
zsh: no matches found: 04.*jpg

in order to avoid the error of files not being found.

Thanks

-- 
Eric Smith


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

* Re: avoid file not found error with { .. } expansion
  2003-12-01 11:17 avoid file not found error with { .. } expansion Eric Smith
@ 2003-12-01 12:02 ` Peter Stephenson
  2003-12-10 12:46   ` regexing to remove punctutation in telephone numbers Eric Smith
  2003-12-01 12:07 ` avoid file not found error with { .. } expansion Thomas Köhler
  1 sibling, 1 reply; 7+ messages in thread
From: Peter Stephenson @ 2003-12-01 12:02 UTC (permalink / raw)
  To: Zsh Users

Eric Smith wrote:
> What would be the correct invocation for this:
> 
> $ xview {02..19}.*jpg
> zsh: no matches found: 04.*jpg
> 
> in order to avoid the error of files not being found.

The main thing to remember is the mantra `brace expansion is not
globbing'.  When you use braces, all elements are generated regardless.
Here, you get:

  xview 02.*jpg 03.*jpg 04.*jpg  ...  19.*jpg

before globbing kicks in.

Are you simply trying to match a set of numbered files of which you're
pretty sure some are there, but not all?  Then the obvious thing to try
is:

 xview <2-19>.*jpg

There's no special handling for a leading zero here, but it will match
one if present.

If you want to be strict about the numeric format, then you need to keep
the braces.  Luckily, in this case you still have the `*', so the set
of arguments generated are still globbing patterns.  Thus you can get
away with:

  xview {02..19}.*jpg(N)

which turns on the NULL_GLOB option for all the patterns.  Then any that
don't match anything will simply be removed.

What you *might* want in this case is for an error to be caused if and
only if there were no matches to any pattern.  With the form in angle
brackets, that's what you get with your current option settings (since
there is only one pattern).  With the form in braces, you would need to
`setopt csh_null_glob' to get this:

  setopt cshnullglob
  xview {02..19}.*jpg

-- 
Peter Stephenson <pws@csr.com>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


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

* Re: avoid file not found error with { .. } expansion
  2003-12-01 11:17 avoid file not found error with { .. } expansion Eric Smith
  2003-12-01 12:02 ` Peter Stephenson
@ 2003-12-01 12:07 ` Thomas Köhler
  1 sibling, 0 replies; 7+ messages in thread
From: Thomas Köhler @ 2003-12-01 12:07 UTC (permalink / raw)
  To: Eric Smith; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 531 bytes --]

Eric Smith wrote:
> What would be the correct invocation for this:
> 
> $ xview {02..19}.*jpg
> zsh: no matches found: 04.*jpg
> 
> in order to avoid the error of files not being found.

I think you want something like this :-)

xview <02-19>*.jpg

Ciao,
Thomas

-- 
 Thomas Köhler       Email:       jean-luc@picard.franken.de
     <><             WWW:           http://jeanluc-picard.de
                     IRC:                           tkoehler
                     PGP public key available from Homepage!

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

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

* regexing to remove punctutation in telephone numbers
  2003-12-01 12:02 ` Peter Stephenson
@ 2003-12-10 12:46   ` Eric Smith
  2003-12-10 13:03     ` Peter Stephenson
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Smith @ 2003-12-10 12:46 UTC (permalink / raw)
  To: Zsh Users

Could someone suggest a neat zsh way to convert

$ myfax 00-(123) 4567-890 _some_file_name_ AnotherFileName.ps whatever

to

001234567890 _some_file_name_ AnotherFileName.ps whatever

thanks a lot ...

-- 
Eric Smith


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

* Re: regexing to remove punctutation in telephone numbers
  2003-12-10 12:46   ` regexing to remove punctutation in telephone numbers Eric Smith
@ 2003-12-10 13:03     ` Peter Stephenson
  2003-12-10 13:17       ` Eric Smith
  0 siblings, 1 reply; 7+ messages in thread
From: Peter Stephenson @ 2003-12-10 13:03 UTC (permalink / raw)
  To: Zsh users list

Eric Smith wrote:
> Could someone suggest a neat zsh way to convert
> 
> $ myfax 00-(123) 4567-890 _some_file_name_ AnotherFileName.ps whatever
> 
> to
> 
> 001234567890 _some_file_name_ AnotherFileName.ps whatever

I don't know how flexible you want to be, but:

myfax () {
        command myfax "${1//[-()]}${2//[-()]}" ${argv[3,-1]}
}

removes the offending characters from the first two arguments and
joins them together.

pws


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


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

* Re: regexing to remove punctutation in telephone numbers
  2003-12-10 13:03     ` Peter Stephenson
@ 2003-12-10 13:17       ` Eric Smith
  2003-12-10 13:44         ` Oliver Kiddle
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Smith @ 2003-12-10 13:17 UTC (permalink / raw)
  To: Zsh users list

Peter Stephenson said:
> Eric Smith wrote:
> > Could someone suggest a neat zsh way to convert
> > 
> > $ myfax 00-(123) 4567-890 _some_file_name_ AnotherFileName.ps whatever
> > 
> > to
> > 
> > 001234567890 _some_file_name_ AnotherFileName.ps whatever
> 
> I don't know how flexible you want to be, but:

Thanks Peter,

Thats exactly the point ...

> 
> myfax () {
>         command myfax "${1//[-()]}${2//[-()]}" ${argv[3,-1]}
> }

There can be n number of args with the offending punctutation characters.  
And n should be determined from the first arg that commences in a non
[-()0-9] character.

-- 
Eric Smith


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

* Re: regexing to remove punctutation in telephone numbers
  2003-12-10 13:17       ` Eric Smith
@ 2003-12-10 13:44         ` Oliver Kiddle
  0 siblings, 0 replies; 7+ messages in thread
From: Oliver Kiddle @ 2003-12-10 13:44 UTC (permalink / raw)
  To: Eric Smith; +Cc: Zsh users list

Eric Smith wrote:
> 
> > 
> > myfax () {
> >         command myfax "${1//[-()]}${2//[-()]}" ${argv[3,-1]}
> > }
> 
> There can be n number of args with the offending punctutation characters.  
> And n should be determined from the first arg that commences in a non
> [-()0-9] character.

myfax() {
  local last=${argv[(i)[^-()0-9]*]}
 
  command myfax "${(j..)argv[1,last-1]//[-()]}" "$argv[last,-1]"   
}

That uses the (i) subscript flag to find the first arg commencing with
a different character. I'd be inclined to check all characters:
  (^[-()0-9]#)
You could use a loop to do the same.


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

end of thread, other threads:[~2003-12-10 13:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-01 11:17 avoid file not found error with { .. } expansion Eric Smith
2003-12-01 12:02 ` Peter Stephenson
2003-12-10 12:46   ` regexing to remove punctutation in telephone numbers Eric Smith
2003-12-10 13:03     ` Peter Stephenson
2003-12-10 13:17       ` Eric Smith
2003-12-10 13:44         ` Oliver Kiddle
2003-12-01 12:07 ` avoid file not found error with { .. } expansion Thomas Köhler

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).