Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Sed : select lines between two timestamps

I want to select lines between two timestamps – 60 minutes before and now

My command is

sed -n '/"$(date -d '60 minutes ago'  +"%H:%m")"/,/"$(date -d  +"%H:%m")"/p'  /var/www/html/glpi/files/_log/event.log/

But i get :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

sed: -e expression #1, char 14: unterminated address regex

>Solution :

In single quotes, $( and " are not treated specially, and single quotes don’t nest.

You also probably don’t want to use the %H:%m format, as it means hour:month.

sed -n "/$(date -d 60\ minutes\ ago +%H:%M)/,\$p"

But if the exact time wasn’t logged, it wouldn’t work. It might be better to use a more powerful language than sed that can actually parse the timestamps and compare them properly.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading