The awk
command is in single quotes so $S_DATE
and $E_DATE
are being taken literally. You have a few options:
#!/usr/local/bin/bash
f_name="test.stat" S_Date="2012-02-10" E_Date="2012-02-13"
awk 'BEGIN {FS="\t";s_time = mktime('"$S_Date"');e_time = mktime('"$E_Date"');counter=0} {if($1 >= s_time && $1 <= e_time) counter++} END{print counter}' "$f_name"
#!/usr/local/bin/bash
f_name="test.stat" S_Date="2012-02-10" E_Date="2012-02-13"
awk "BEGIN {FS=\"\\t\";s_time = mktime($S_Date);e_time = mktime($E_Date);counter=0} {if(\$1 >= s_time && \$1 <= e_time) counter++} END{print counter}" "$f_name"
Or, my favorite:
#!/usr/local/bin/bash
f_name="test.stat" S_Date="2012-02-10" E_Date="2012-02-13"
awk "$f_name" <<EOF
BEGIN {
FS="\t"
s_time = mktime($S_Date)
e_time = mktime($E_Date)
counter=0
}
{ if(\$1 >= s_time && \$1 <= e_time) counter++ }
END{print counter}
EOF