Grep log between range of minutes

grep -i "$(date +%b" "%d )13:4[0-5]" syslog
Returns logs between HH:M[Mx-My], for example, between 13:40 and 13:45.
Sample Output
May 23 13:45:01 tortatil /USR/SBIN/CRON[22944]: (root) CMD (pidof cpulimit || cpulimit -z -p  `pidof amule` -l 24 &)
May 23 13:45:01 tortatil /USR/SBIN/CRON[22947]: (root) CMD (if [ -x /usr/bin/mrtg ] && [ -r /etc/mrtg.cfg ]; then mkdir -p /var/log/mrtg ; env LANG=C /usr/bin/mrtg /etc/mrtg.cfg 2>&1 | tee -a /var/log/mrtg/mrtg.log ; fi

2010-05-23 16:30:46

What Others Think

That kind of things cannot be easily adapted to grep range of minutes like : 39-45. Depending on your input, the use of awk may be a wise choice.
Josay · 631 weeks and 1 day ago
Backticks are more harm than good. Learn the way of the Jedi: grep -i "$(date +%b" "%d" ")13:4[0-5]" syslog
atoponce · 631 weeks and 1 day ago
be carefull because sometimes you may have date inside log messages, for example : Nov 23 13:53:16 my_mx postfix/scache[29106]: statistics: start interval Nov 23 13:43:16 so try this : grep -i ^"$(date +%b" "%d" ")13:4[0-5]" syslog
gerard · 552 weeks and 6 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: