Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You have to look at every single line in the range you want (to tell if it's in the range you want) so I'm guessing you mean not every line in the file. At a bare minimum, you will have to look at every line in the file up to and including the first one outside your range (I'm assuming the lines are in date/time order).</p> <p>This is a fairly simple pattern:</p> <pre><code>state = preprint for every line in file: if line.date &gt;= startdate: state = print if line.date &gt; enddate: exit for loop if state == print: print line </code></pre> <p>You can write this in awk, Perl, Python, even COBOL if you must but the logic is always the same.</p> <p>Locating the line numbers first (with say grep) and then just blindly printing out that line range won't help since grep also has to look at all the lines (<em>all</em> of them, not just up to the first outside the range, and most likely <em>twice</em>, one for the first line and one for the last).</p> <p>If this is something you're going to do quite often, you may want to consider shifting the effort from 'every time you do it' to 'once, when the file is stabilized'. An example would be to load up the log file lines into a database, indexed by the date/time.</p> <p>That takes a while to get set up but will result in your queries becoming a lot faster. I'm not necessarily advocating a database - you could probably achieve the same effect by splitting the log files into hourly logs thus:</p> <pre><code>2009/ 01/ 01/ 0000.log 0100.log : : 2300.log 02/ : : </code></pre> <p>Then for a given time, you know exactly where to start and stop looking. The range <code>2009/01/01-15:22</code> through <code>2009/01/05-09:07</code> would result in:</p> <ul> <li>some (the last bit) of the file <code>2009/01/01/1500.txt</code>.</li> <li>all of the files <code>2009/01/01/1[6-9]*.txt</code>.</li> <li>all of the files <code>2009/01/01/2*.txt</code>.</li> <li>all of the files <code>2009/01/0[2-4]/*.txt</code>.</li> <li>all of the files <code>2009/01/05/0[0-8]*.txt</code>.</li> <li>some (the first bit) of the file <code>2009/01/05/0900.txt</code>.</li> </ul> <p>Of course, I'd write a script to return those lines rather than trying to do it manually each time.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload