Grep for last X hours
<p>I have a log file. Each line is prepended with a date and the date format is as below:</p>

<pre><code>2016-02-01 11:34:48,567.......
</code></pre>

<p>How do I <code>grep</code> this file for last 24 hours?</p>

<p>I tried few things such as below for specific time but this approach wont work for last X hours:</p>

<pre><code>grep "2016-02-01 15:0[1-9]:00 logfile
</code></pre>

<p>Also, the following does work for -1hour but fails for -23 or -24hours:</p>

<pre><code> grep "^$(date -d -23hour +'%Y-%m-%d %H')" logfile
</code></pre>