using regular expression in for loop

Hi,

i want to use regular expression in a for loop like this.

for var in "[1-3][0-6]/Mar/2010"
do
echo "Usage for the date $var"
-----and want to grep $var partten from a file--------
done

and it is not working.

I am new to shell scripting, any one has any idea how to do it.

1.: Put your code in code tags (select it and use the '#' button).
2.: What isn't working? error? output?
2.: What is the desired effect of your script?
3.: What values do you want to give to your $var?

for var in "[0-3][1-9]/Mar/2010"
do
echo "Usage for the date $var"
-----and want to grep $var partten from a file--------
done

here wat i am expecting is, this string "[0-3][1-9]/Mar/2010" give me string from 01/Mar/2010-30/Mar/2010 in the for loop.

and this regular expression is not giving the desired result.

Any suggestion ???

If it should work it would give 01 to 39...
if you have seq you can

for i in $(seq -w 30)
do
    var="$i/Mar/2010"
    echo "Usage for the date $var"
done

Or you can use the while loop.
In my Bash shell, for example -

$
$
$ day=1
$ while [ $day -le 31 ]; do
>   var=`printf "%02d/Mar/2010\n" $day`
>   echo "Usage for the date: $var"
>   day=`expr $day + 1`
> done
Usage for the date: 01/Mar/2010
Usage for the date: 02/Mar/2010
Usage for the date: 03/Mar/2010
Usage for the date: 04/Mar/2010
Usage for the date: 05/Mar/2010
Usage for the date: 06/Mar/2010
Usage for the date: 07/Mar/2010
Usage for the date: 08/Mar/2010
Usage for the date: 09/Mar/2010
Usage for the date: 10/Mar/2010
Usage for the date: 11/Mar/2010
Usage for the date: 12/Mar/2010
Usage for the date: 13/Mar/2010
Usage for the date: 14/Mar/2010
Usage for the date: 15/Mar/2010
Usage for the date: 16/Mar/2010
Usage for the date: 17/Mar/2010
Usage for the date: 18/Mar/2010
Usage for the date: 19/Mar/2010
Usage for the date: 20/Mar/2010
Usage for the date: 21/Mar/2010
Usage for the date: 22/Mar/2010
Usage for the date: 23/Mar/2010
Usage for the date: 24/Mar/2010
Usage for the date: 25/Mar/2010
Usage for the date: 26/Mar/2010
Usage for the date: 27/Mar/2010
Usage for the date: 28/Mar/2010
Usage for the date: 29/Mar/2010
Usage for the date: 30/Mar/2010
Usage for the date: 31/Mar/2010
$
$

tyler_durden

Learning the shell can be a bit eccentric sometimes ;-}

I >>think<< that you are confusing a few basic concepts.

Bash regular expressions would be more likely used in string manipulation.

You can read extensively about it here:

Manipulating Strings

Reading your code, it looks suspiciously like what you are trying to use is brace expansion of this type:

$ for var in {0..3}{1..9}; do echo -n "$var "; done
01 02 03 04 05 06 07 08 09 11 12 13 14 15 16 17 18 19 21 22 23 24 25 26 27 28 29 31 32 33 34 35 36 37 38 39 

Double braces expansion is similar to a nested loop. This is not a great shortcuts for dates, however, since there are different number of days per month.

Single brace expansion is a great shortcut for this though:

$ # First day of every month in 2010:
$ for var in {1..12}; do echo -n "$var/1/2010 "; done 
1/1/2010 2/1/2010 3/1/2010 4/1/2010 5/1/2010 6/1/2010 7/1/2010 8/1/2010 9/1/2010 10/1/2010 11/1/2010 12/1/2010

or this:

$ # Every day in March 2010 (US Style...)
$ for var in {1..31}; do echo "3/$var/2010 "; done
3/1/2010 
3/2/2010 
3/3/2010 
3/4/2010 
3/5/2010 
3/6/2010 
3/7/2010 
3/8/2010 
3/9/2010 
3/10/2010 
3/11/2010 
3/12/2010 
3/13/2010 
3/14/2010 
3/15/2010 
3/16/2010 
3/17/2010 
3/18/2010 
3/19/2010 
3/20/2010 
3/21/2010 
3/22/2010 
3/23/2010 
3/24/2010 
3/25/2010 
3/26/2010 
3/27/2010 
3/28/2010 
3/29/2010 
3/30/2010 
3/31/2010