zsh-users
 help / color / mirror / code / Atom feed
* trying to match yyyy-mm-dd what am I missing?
@ 2005-09-02 19:20 Timothy Luoma
  2005-09-02 19:34 ` Artur Penttinen
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Timothy Luoma @ 2005-09-02 19:20 UTC (permalink / raw)
  To: zsh-users

I am trying to match all folders in the CWD which are in the format  
YYYY-MM-DD.

Actually I'm just trying to match the ones from 2000 so I am using

2[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]

as my regex.

This is my script:

for i in *
do

if [ -d "$i" ]
     then
         if [ "$i" = 2[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] ]
     then
         echo "YES: $i"
     else
         echo "no: $i"
     fi
fi

done

Here are the results:

YES: 2005-08-24/
no: 2005-08-26/
no: 2005-08-27/
no: 2005-08-28/
no: 2005-08-29/
no: access.log/


So it is only matching the first one, and I can't figure out why.

TjL

ps - actually I eventually want to match any file/folder that is NOT  
(a directory AND in yyyy-mm-dd format)




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

* Re: trying to match yyyy-mm-dd what am I missing?
  2005-09-02 19:20 trying to match yyyy-mm-dd what am I missing? Timothy Luoma
@ 2005-09-02 19:34 ` Artur Penttinen
  2005-09-03  2:15 ` Clint Adams
  2005-09-03 13:04 ` Geoff Wing
  2 siblings, 0 replies; 7+ messages in thread
From: Artur Penttinen @ 2005-09-02 19:34 UTC (permalink / raw)
  To: zsh-users

>I am trying to match all folders in the CWD which are in the format  
>YYYY-MM-DD.
>
>Actually I'm just trying to match the ones from 2000 so I am using
>
>2[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]
>
>as my regex.
>
>This is my script:
>
>for i in *
>do
>
>if [ -d "$i" ]
>     then
>         if [ "$i" = 2[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] ]
>     then
>         echo "YES: $i"
>     else
>         echo "no: $i"
>     fi
>fi
>
>done
>
>Here are the results:
>
>YES: 2005-08-24/
>no: 2005-08-26/
>no: 2005-08-27/
>no: 2005-08-28/
>no: 2005-08-29/
>no: access.log/

  # mkdir 2005-08-24 2005-08-26 2005-08-27 2005-08-28 2005-08-29 access.log
  # for i in *(/); do [[ $i == 2[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] ]] && print "$i YES" || print "$i NO"; done
  2005-08-24 YES
  2005-08-26 YES
  2005-08-27 YES
  2005-08-28 YES
  2005-08-29 YES
  access.log NO

-- 
wbw, artur


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

* Re: trying to match yyyy-mm-dd what am I missing?
  2005-09-02 19:20 trying to match yyyy-mm-dd what am I missing? Timothy Luoma
  2005-09-02 19:34 ` Artur Penttinen
@ 2005-09-03  2:15 ` Clint Adams
  2005-09-03 13:04 ` Geoff Wing
  2 siblings, 0 replies; 7+ messages in thread
From: Clint Adams @ 2005-09-03  2:15 UTC (permalink / raw)
  To: Timothy Luoma; +Cc: zsh-users

>     then
>         if [ "$i" = 2[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] ]

I don't know why it would match the first one, but if you have MARK_DIRS
set, that's going to fail.


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

* Re: trying to match yyyy-mm-dd what am I missing?
  2005-09-02 19:20 trying to match yyyy-mm-dd what am I missing? Timothy Luoma
  2005-09-02 19:34 ` Artur Penttinen
  2005-09-03  2:15 ` Clint Adams
@ 2005-09-03 13:04 ` Geoff Wing
  2005-09-03 19:01   ` Timothy Luoma
  2005-09-03 19:06   ` Timothy Luoma
  2 siblings, 2 replies; 7+ messages in thread
From: Geoff Wing @ 2005-09-03 13:04 UTC (permalink / raw)
  To: zsh-users

Timothy Luoma <lists@tntluoma.com> typed:
: I am trying to match all folders in the CWD which are in the format  
: YYYY-MM-DD.
:          if [ "$i" = 2[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] ]

This gets expanded to all the directories matching it.  See
"CONDITIONAL EXPRESSIONS:  ....
 Normal shell expansion is performed on the file, string and pattern
 arguments, but the result of each expansion is constrained to be a
 single word, similar to the effect of double quotes."

You're trying to match each against (in your case with MARK_DIRS set)
"2005-08-24/ 2005-08-26/ 2005-08-27/ 2005-08-28/ 2005-08-29/"

Try a different solution, e.g.:

for i in *(^M)
do

if [ -d "$i" ]; then
     case $i in
        2[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]) echo "YES: $i";;
        *) echo "no: $i" ;;
     esac

fi

done

Regards,
-- 
Geoff Wing


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

* Re: trying to match yyyy-mm-dd what am I missing?
  2005-09-03 13:04 ` Geoff Wing
@ 2005-09-03 19:01   ` Timothy Luoma
  2005-09-04  6:59     ` Artur Penttinen
  2005-09-03 19:06   ` Timothy Luoma
  1 sibling, 1 reply; 7+ messages in thread
From: Timothy Luoma @ 2005-09-03 19:01 UTC (permalink / raw)
  To: zsh-users


On Sep 3, 2005, at 9:04 AM, Geoff Wing wrote:

>   # mkdir 2005-08-24 2005-08-26 2005-08-27 2005-08-28 2005-08-29  
> access.log
>   # for i in *(/); do [[ $i == 2[0-9][0-9][0-9]-[0-9][0-9]-[0-9] 
> [0-9] ]] && print "$i YES" || print "$i NO"; done
>   2005-08-24 YES
>   2005-08-26 YES
>   2005-08-27 YES
>   2005-08-28 YES
>   2005-08-29 YES
>   access.log NO
>

Hrm... that didn't work here:

$ for i in *(/); do [[ $i == 2[0-9][0-9][0-9]-[0-9][0-9]-[0-9] 
[0-9] ]] && print "$i YES" || print "$i NO"; done

2005-08-24/ NO
2005-08-26/ NO
2005-08-27/ NO
2005-08-28/ NO
2005-08-29/ NO
access.log/ NO



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

* Re: trying to match yyyy-mm-dd what am I missing?
  2005-09-03 13:04 ` Geoff Wing
  2005-09-03 19:01   ` Timothy Luoma
@ 2005-09-03 19:06   ` Timothy Luoma
  1 sibling, 0 replies; 7+ messages in thread
From: Timothy Luoma @ 2005-09-03 19:06 UTC (permalink / raw)
  To: zsh-users


On Sep 3, 2005, at 9:04 AM, Geoff Wing wrote:
> Timothy Luoma <lists@tntluoma.com> typed:
> : I am trying to match all folders in the CWD which are in the format
> : YYYY-MM-DD.
> :          if [ "$i" = 2[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] ]
>
> This gets expanded to all the directories matching it.  See
> "CONDITIONAL EXPRESSIONS:  ....
>  Normal shell expansion is performed on the file, string and pattern
>  arguments, but the result of each expansion is constrained to be a
>  single word, similar to the effect of double quotes."

I could have read that 1,000 times and not understood that it applied  
to my situation.

> You're trying to match each against (in your case with MARK_DIRS set)
> "2005-08-24/ 2005-08-26/ 2005-08-27/ 2005-08-28/ 2005-08-29/"

> Try a different solution, e.g.:
>
> for i in *(^M)
> do
>
> if [ -d "$i" ]; then
>      case $i in
>         2[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]) echo "YES: $i";;
>         *) echo "no: $i" ;;
>      esac
>
> fi
>
> done

Ah!  That works!  Thanks.


I am using this, together with the previous script about getting the  
creation date, to easily sort folders with lots of stuff in them into  
folders with contents organized by creation date.

Thanks!
TjL




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

* Re: trying to match yyyy-mm-dd what am I missing?
  2005-09-03 19:01   ` Timothy Luoma
@ 2005-09-04  6:59     ` Artur Penttinen
  0 siblings, 0 replies; 7+ messages in thread
From: Artur Penttinen @ 2005-09-04  6:59 UTC (permalink / raw)
  To: lists; +Cc: zsh-users

>
>On Sep 3, 2005, at 9:04 AM, Geoff Wing wrote:
>
>>   # mkdir 2005-08-24 2005-08-26 2005-08-27 2005-08-28 2005-08-29  
>> access.log
>>   # for i in *(/); do [[ $i == 2[0-9][0-9][0-9]-[0-9][0-9]-[0-9] 
>> [0-9] ]] && print "$i YES" || print "$i NO"; done
>>   2005-08-24 YES
>>   2005-08-26 YES
>>   2005-08-27 YES
>>   2005-08-28 YES
>>   2005-08-29 YES
>>   access.log NO
>>
>
>Hrm... that didn't work here:
>
>$ for i in *(/); do [[ $i == 2[0-9][0-9][0-9]-[0-9][0-9]-[0-9] 
>[0-9] ]] && print "$i YES" || print "$i NO"; done
>
>2005-08-24/ NO
>2005-08-26/ NO
>2005-08-27/ NO
>2005-08-28/ NO
>2005-08-29/ NO
>access.log/ NO

  setopt extendedglob

-- 
wbw, artur


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

end of thread, other threads:[~2005-09-04  7:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-02 19:20 trying to match yyyy-mm-dd what am I missing? Timothy Luoma
2005-09-02 19:34 ` Artur Penttinen
2005-09-03  2:15 ` Clint Adams
2005-09-03 13:04 ` Geoff Wing
2005-09-03 19:01   ` Timothy Luoma
2005-09-04  6:59     ` Artur Penttinen
2005-09-03 19:06   ` Timothy Luoma

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