zsh-users
 help / color / mirror / code / Atom feed
* Glob for specific length?
@ 2010-11-22 19:29 Aaron Davies
  2010-11-22 19:59 ` Benjamin R. Haskell
  2010-11-23  8:19 ` Frank Terbeck
  0 siblings, 2 replies; 5+ messages in thread
From: Aaron Davies @ 2010-11-22 19:29 UTC (permalink / raw)
  To: zsh-users

Is there a glob for files with names of e.g. exactly thirty
characters? sort of the equiv of /^.{30}$/

-- 
Aaron Davies
aaron.davies@gmail.com


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

* Re: Glob for specific length?
  2010-11-22 19:29 Glob for specific length? Aaron Davies
@ 2010-11-22 19:59 ` Benjamin R. Haskell
  2010-11-23  8:19 ` Frank Terbeck
  1 sibling, 0 replies; 5+ messages in thread
From: Benjamin R. Haskell @ 2010-11-22 19:59 UTC (permalink / raw)
  To: Aaron Davies; +Cc: zsh-users

On Mon, 22 Nov 2010, Aaron Davies wrote:

> Is there a glob for files with names of e.g. exactly thirty 
> characters? sort of the equiv of /^.{30}$/

I don't know whether there's a more concise one, but this works to `ls` 
the ones that match:

ls -l *(e:'[[ $#REPLY == 30 ]] || reply=()':)

You could also wrap the expression there into a function:

globlen() { [[ $#REPLY == $GLOBLEN ]] || reply=() }
GLOBLEN=30
ls -l *(+globlen)

More info:

man zshall | less +/estring

-- 
Best,
Ben


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

* Re: Glob for specific length?
  2010-11-22 19:29 Glob for specific length? Aaron Davies
  2010-11-22 19:59 ` Benjamin R. Haskell
@ 2010-11-23  8:19 ` Frank Terbeck
  2010-11-23 15:11   ` Aaron Davies
  1 sibling, 1 reply; 5+ messages in thread
From: Frank Terbeck @ 2010-11-23  8:19 UTC (permalink / raw)
  To: Aaron Davies; +Cc: zsh-users

Aaron Davies wrote:
> Is there a glob for files with names of e.g. exactly thirty
> characters? sort of the equiv of /^.{30}$/

Yes. See zshexpn(1) for (#cN,M).

Example:

% ls -lad ls -lad /?(#c3)
drwxr-xr-x   2 root root   4096 Nov  2 23:31 /bin
drwxr-xr-x  15 root root   3460 Nov 22 23:12 /dev
drwxr-xr-x 161 root root  12288 Nov 22 14:20 /etc
drwxr-xr-x  14 root root  12288 Oct 22 09:43 /lib
drwxrwxr-x   8 root staff  4096 Nov 13 22:26 /mnt
drwxr-xr-x   4 root root   4096 Oct  4 11:05 /opt
drwxr-xr-x   4 root root   4096 Apr 29  2010 /srv
drwxr-xr-x  12 root root      0 Oct 22 09:50 /sys
drwxrwxrwt  22 root root  12288 Nov 23 09:15 /tmp
drwxr-xr-x  15 root root   4096 Oct  3 12:31 /usr
drwxr-xr-x  16 root root   4096 Jul  1 19:41 /var

Regards, Frank

-- 
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
                                                  -- RFC 1925


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

* Re: Glob for specific length?
  2010-11-23  8:19 ` Frank Terbeck
@ 2010-11-23 15:11   ` Aaron Davies
  2010-11-23 15:18     ` Frank Terbeck
  0 siblings, 1 reply; 5+ messages in thread
From: Aaron Davies @ 2010-11-23 15:11 UTC (permalink / raw)
  To: Frank Terbeck; +Cc: zsh-users

I can't get this to work. It's new in 4.3.5, right, so it should be in 4.3.9?

I don't understand the commandline you gave (is there a paste error in
it?) and when I try it, I get "zsh: unknown file attribute".

On Tuesday, November 23, 2010, Frank Terbeck  wrote:
> Aaron Davies wrote:
>> Is there a glob for files with names of e.g. exactly thirty
>> characters? sort of the equiv of /^.{30}$/
>
> Yes. See zshexpn(1) for (#cN,M).
>
> Example:
>
> % ls -lad ls -lad /?(#c3)
> drwxr-xr-x   2 root root   4096 Nov  2 23:31 /bin
> drwxr-xr-x  15 root root   3460 Nov 22 23:12 /dev
> drwxr-xr-x 161 root root  12288 Nov 22 14:20 /etc
> drwxr-xr-x  14 root root  12288 Oct 22 09:43 /lib
> drwxrwxr-x   8 root staff  4096 Nov 13 22:26 /mnt
> drwxr-xr-x   4 root root   4096 Oct  4 11:05 /opt
> drwxr-xr-x   4 root root   4096 Apr 29  2010 /srv
> drwxr-xr-x  12 root root      0 Oct 22 09:50 /sys
> drwxrwxrwt  22 root root  12288 Nov 23 09:15 /tmp
> drwxr-xr-x  15 root root   4096 Oct  3 12:31 /usr
> drwxr-xr-x  16 root root   4096 Jul  1 19:41 /var
>
> Regards, Frank
>
> --
> In protocol design, perfection has been reached not when there is
> nothing left to add, but when there is nothing left to take away.
>                                                   -- RFC 1925
>

-- 
Aaron Davies
aaron.davies@gmail.com


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

* Re: Glob for specific length?
  2010-11-23 15:11   ` Aaron Davies
@ 2010-11-23 15:18     ` Frank Terbeck
  0 siblings, 0 replies; 5+ messages in thread
From: Frank Terbeck @ 2010-11-23 15:18 UTC (permalink / raw)
  To: Aaron Davies; +Cc: zsh-users

Aaron Davies wrote:
> I can't get this to work. It's new in 4.3.5, right, so it should be in 4.3.9?
>
> I don't understand the commandline you gave (is there a paste error in
> it?) and when I try it, I get "zsh: unknown file attribute".

setopt extended_glob

-- 
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
                                                  -- RFC 1925


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

end of thread, other threads:[~2010-11-23 15:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-22 19:29 Glob for specific length? Aaron Davies
2010-11-22 19:59 ` Benjamin R. Haskell
2010-11-23  8:19 ` Frank Terbeck
2010-11-23 15:11   ` Aaron Davies
2010-11-23 15:18     ` Frank Terbeck

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