D
D
Dima Petrov2019-05-24 09:19:02
bash
Dima Petrov, 2019-05-24 09:19:02

How to compare the received date from a string in awk and print the string?

so I just get the date, you need to compare it with

echo '12.23.55.11 - - [24/May/2019:08:51:35 +0300] "GET /site/play?cam=1105 HTTP/1.1"' | sed -e 's/\// /' -e 's/\// /' -e '0,/:/s// /' -e '0,/\ +..../s///' -e 's/]/] - /' -e 's/\]//' -e 's/\[//' | awk -F '-' '{print $3}'

it is required that awk compares the converted date to unix timestamp if it is greater than output the string.
echo '22 May 2019 12:49:52' | awk m =`date -d'$0' +%s`  m < 1558518592 /var/log/httpd/access_log

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Heizenberg, 2019-05-24
@sajor2006

Alternatively, parse the logs with awk
awk -vDate=`date -d'now-2 hours' +[%d/%b/%Y:%H:%M:%S` '$4 > Date {print Date, $0 }' access_log Taken
from here.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question