awk '/10:..:/, /13:..:/' server.log > /tmp/awktmp
I tried this command as someone gave me. It worked for me to find logs between 10:00 AM to 13:00 PM but I don't understand it fully.
Please tell me an elegant solution if you've one. Remember the remote servers are minimal and don't have advanced utilities.
What I don't understand here is '/10:..:/, /13:..:/'
- I understand
10:..
means10
and:
and match exactly 2 digits. - But what does another
:
mean?
I suppose the forwardslashes are for putting regular expression like we do in JavaScript regex. I'm not 100% sure about that.
Update 1:
Time is in second column, in format HH:MM:SS
Update 2:
sed -n -e '/8:..:../,/9:..:../p' application.log > /tmp/sedtmp
I tried this but this is also showing logs from 07:57:47
.
Update 3
The logs don't always contain the timestamp in each row. Some rows don't contain any timestamp at all. How'd you overcome that issue? I stupidly used awk and I missed all the rows which didn't have time value in them. Is there a way to avoid this issue?
Like this is what I mean.
2023-08-07 09:20:35 0123456789 INFO CustomerLogoutResource:95 - Entering logout api.
2023-08-07 09:20:35 0123456789 ERROR AppExceptionMapper:87 - Exception has been thrown by container
2023-08-07 09:20:35 0123456789 ERROR AppExceptionMapper:555 - Unchecked Exception
java.lang.NullPointerException
at NullPointerExceptionExample.printLength(NullPointerExceptionExample.java:3)
at NullPointerExceptionExample.main(NullPointerExceptionExample.java:8)