I want to find a date in a log file and print from that date till the end of log file and that date is 5 days prior to the end of log file which is 27/Dec/2002
the log file is like this : 213.64.56.208 - - [01/Jan/2003:05:42:53 +0100]
the whole script :
for d in \
$(sed -nre 's/.*\[(..)\/(...)\/(....):(..:..:..) .*/\1 \2 \3 \4/p' thttpd.log $
do echo $d >s1; done
time=$(expr 60 \* 60 \* 24 \* 5)
EDATE=`tail -1 s1`
SDATE=$[$EDATE - $time]
sd=`date -d '1970-01-01 UTC '$SDATE' seconds' +"%d/%b/%Y"`
sd=$(echo $sd | sed 's/\//\\\//g')
sed -n "$(awk '/'$sd'/ { print NR }' thttpd.log | head -1),$ p" thttpd.log
the problem is the date 27/Dec/2002 is not in log file ! so now how should i write to go for searching the next day (28/Dec/2002)
213.64.237.213 - - [23/Dec/2002:03:02:22 +0100]
213.132.36.66 - - [28/Dec/2002:19:33:29 +0100]
I also have this problem with hour too ! I want to print the last 5 hour which would be 07:55:21 , but there is not 7:55 in the log file ! so it should print from the next item till (08:08) the end
213.64.56.208 - - [01/Jan/2003:07:53:17 +0100]
213.64.56.208 - - [01/Jan/2003:08:08:19 +0100]