user2877617
user2877617

Reputation:

How can I print all lines generated in a given time interval in sed

I have to print all lines from /var/log/messages that were generated between 11pm and 12 midnight. I used this code

sed -n -e '/23:00:00/,/00:00:00/p' /var/log/messages

But output is not displaying.I tried for another time interval.It works only when the accurate time in the message file is given.

eg:sed -n -e '/23:50:01/,/23:59:09/p' /var/log/messages

Please help Thank you

Upvotes: 1

Views: 191

Answers (3)

Jotne
Jotne

Reputation: 41456

You can try this with awk

awk '$0>=from && $0<=to' from="23:00:00" to="00:00:00" /var/log/messages

Upvotes: 0

JackDVD
JackDVD

Reputation: 164

sed -n -r -e '/ (00:00:00|23:[0-6][0-9]:[0-6][0-9]) /p' /var/log/messages

If you don't need the messages at 00:00:00 then just use

sed -n -e '/ 23:[0-6][0-9]:[0-6][0-9] /p' /var/log/messages

Upvotes: 0

micheal.yxd
micheal.yxd

Reputation: 128

because 23:00:00 doesn't show in /var/log/message.

you can try this:

sed -n -e '/23:[0-6][0-9]:[0-6][0-9]/, /00:[0-6][0-9]:[0-6][0-9]/p' /var/log/messages

Upvotes: 1

Related Questions