I am trying to extract time range from a logfile by passing shell variables in awk. This is how my log file is.
2014-11-24 12:58:59.290 1.1.1.1 etc..
2014-11-24 13:58:59.290 2.2.2.2 etc..
2014-11-24 14:58:59.290 3.3.3.3 etc ..
2014-11-24 12:58:59.290 4.4.4.4 etc..
2014-11-24 15:58:59.290 4.4.4.4 etc..
Suppose I want to extract time range between 12 hours and 13 hours. Here is the bash script I have written.
stime=12
etime=13
date_=2014-11-24
awk 'BEGIN {
a='$stime';b='$etime';d='$date_'; FS="[: ]"
}
{
if ( $1 == d && $2 >= a && $2 < b )
print $1 $2 $3
}' logfile.txt
My output should look like this.
2014-11-24 12:58:59.290 1.1.1.1 etc..
2014-11-24 12:58:59.290 4.4.4.4 etc..
I don't see any output nor any errors. I don't know what's is going wrong. Any help with this would be appreciated. Thank you
;doing inside yourFS?