-1

This question already has an answer here:

I am using below command to display log data for last 10 mins. It works fine if the month stays same however when month is changed it doesn't show any data.

awk -v d1="$D1" -v d2="$D2" '$0 > d1 && $0 < d2 || $0 ~ d2' /home/user.log

Works fine if,

D1="Aug  1 12:00:00"
D2="Aug  1 12:10:00"

But doesn't show any data if,

D1="Jul 31 11:55:00"
D2="Aug  1 00:05:00"

P.S I am using AIX

marked as duplicate by msp9011, Rui F Ribeiro, Jeff Schaller, countermode, schily Aug 29 '18 at 12:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

I believe that's because it's really comparing the strings, not the dates. When the month changes it breaks the comparison.

Try formatting the date another way, maybe using epoch or numeric date format.

date -d "Jul 31 11:55:00" +%s

outputs 1533063300. Similarly,

date -d "Aug  1 00:05:00" +%s

outputs 1533107100.

Should be an easy comparison from there.

Not the answer you're looking for? Browse other questions tagged or ask your own question.