How to Compare timestamp

Hi,
my script is accepting the time from user. Then I have to select all records from file that lie between the time stamp supplied by user.

For eg
File format:
-----------

25-01-2012,20:06:27, ,09454545455,099999999999999,105,105, , ,TTK32,9999, ,PPUU, ,O, ,99, , ,
25-01-2012,20:06:39, ,09454545455,099999999999999,994,994, , ,TTK32,9999, ,PPUU, ,O, ,99, , ,
25-01-2012,20:06:39, ,094545455,099999999999999,88,88, , ,TTK32,9999, ,MUO2, ,O, ,99, , ,
25-01-2012,20:06:42, ,094545455,099999999999999,96,96, , ,TTK32,9999, ,PPUU, ,O, ,99, , ,
25-01-2012,20:06:43, ,094545455,0999999999999,111,111, , ,TTK32,9999, ,PPUU, ,O, ,99, , ,
25-01-2012,20:06:43, ,09455455,099999999999999,115,115, , ,TTK32,9999, ,PPUU, ,O, ,99, , ,
25-01-2012,20:06:44, ,09454545455,099999999999999,83,83, , ,TTK32,9999, ,PPUU, ,O, ,99, , ,
25-01-2012,20:06:51, ,09454545455,099999999999,114,114, , ,TTK32,9999, ,PPUU, ,O, ,99, , ,
25-01-2012,20:06:52, ,094545455,099999999999999,161,161, , ,TTK32,9999, ,PPUU, ,O, ,99, , ,
25-01-2012,20:06:52, ,09454545455,099999999999,96,96, , ,TTK32,9999, ,PPUU, ,O, ,99, , ,
25-01-2012,20:06:53, ,09454545455,099999999999999,91,91, , ,TTK32,9999, ,PPUU, ,O, ,99, , ,

if The user is supplying

Time1=20:06:00
Time1=20:09:00

then we have to select all records whose time stamp is between these 2 times

Please suggest.

Your requirement doesn't see to be real.
what about the date?
Does your database/file contain the data only for the sysdate?

U can try by converting time H:M to Seconds and compare that ...

How about an alphabetic comparison?

awk -F, -v T1="20:06:00" -v T2="20:09:00" '(T1>=$2)&&(T2<=$2)'

Thanks Corona...
But it is giving error...

gunzip -c ABCDEF.gz | awk -F, -v T1="20:00:00" -v T2="20:01:00" '{if(T1>=$2)&&(T2<=$2) print $0'

error is:

 Syntax Error The source line is 1.
 The error context is
                 >>> {if(T1>=$2)&& <<<
 awk: 0602-502 The statement cannot be correctly parsed. The source line is 1.
c1=`echo $1 | awk -F":" '{print $1$2$3}'`
c2=`echo $2 | awk -F":" '{print $1$2$3}'`

cat file | while read line
do
c=`echo $line | cut -f2 -d"," | awk -F":" '{print $1$2$3}'`

if [ $c -gt $c1 -a  $c -lt $c2 ];then
echo $line
fi
done

Try the code I actually gave you instead of rewriting it into something broken.

The version you wrote is very redundant( X { print $0 } is equivalent to just X ) and missing tons of important brackets -- i.e. you forgot the ending }, and didn't put the if-statement in its own ().

awk '/,20:06:/,/.20:09:/' inputfile

thanks chihung....but 20:06 and 20:09 are variables..that are supplied by the user...how to pass variables...

Have you tried my code which lets you pass in variables?

#! /bin/bash

t1=$1
t2=$2

while read x
do
    t=`echo $x | cut -d, -f2 | tr -d ':'`
    [ $t -ge $t1 -a $t -le $t2 ] && echo $x
done < inputfile
$ ./test.sh 200630 200930
25-01-2012,20:06:39, ,09454545455,099999999999999,994,994, , ,TTK32,9999, ,PPUU, ,O, ,99, , ,
25-01-2012,20:06:39, ,094545455,099999999999999,88,88, , ,TTK32,9999, ,MUO2, ,O, ,99, , ,
25-01-2012,20:06:42, ,094545455,099999999999999,96,96, , ,TTK32,9999, ,PPUU, ,O, ,99, , ,
25-01-2012,20:06:43, ,094545455,0999999999999,111,111, , ,TTK32,9999, ,PPUU, ,O, ,99, , ,
25-01-2012,20:06:43, ,09455455,099999999999999,115,115, , ,TTK32,9999, ,PPUU, ,O, ,99, , ,
25-01-2012,20:07:44, ,09454545455,099999999999999,83,83, , ,TTK32,9999, ,PPUU, ,O, ,99, , ,
25-01-2012,20:08:51, ,09454545455,099999999999,114,114, , ,TTK32,9999, ,PPUU, ,O, ,99, , ,

You should also try searching the forum for similar posts.