comparing variables to date as string

I have a file

$ cat myfile
A 02/16/2012
B 02/19/2012
C 02/20/2012
D 02/17/2012
E 02/16/2012

My simple script

> cat myscript.sh
 
mydate="02/16/2012"
awk ' ($2~/$mydate/) {print $1}' < myfile

but I got no output! and when I try $2~/'$mydate'/

I got: The error context is

                 >>>  ($2~/02/16/2012/) <<<

I need your help please

$ awk -v dt=$mydate '$2 ~ dt{print $1}' myfile
A
E

Guru.

1 Like

Thanks, It is working