Hi,
(This solution is in PHP -- but you can probably do that directly from the command-line, I suppose, with somekind of grep or anything)
Considering your dates are in the YYYY-MM-DD
format, and that they are at the beginning of each line, you just have to compare the lines alphabetically to compare the dates.
One solution would be to :
- load the string
- explode it by lines
- remove the first line
- iterate over the lines, keeping only those that interest you
For the first parts :
$str = <<<STR
date,test,time,avail
2009-09-01,JS,0.119,99.90
2009-09-02,JS,0.154,99.89
2009-09-03,SWF,0.177,99.90
2009-09-04,SWF,0.177,99.90
2009-09-05,SWF,0.177,99.90
2009-09-06,SWF,0.177,99.90
2009-09-07,SWF,0.177,99.90
2009-09-08,SWF,0.177,99.90
2009-09-09,SWF,0.177,99.90
2009-09-10,SWF,0.177,99.90
STR;
$lines = explode(PHP_EOL, $str);
unset($lines[0]); // first line is useless
And, to iterate over the lines, filtering in/out those you want / don't want, you could use a foreach loop... Or use the array_filter
function, which exists just for this ;-)
For instance, you could use something like this :
$new_lines = array_filter($lines, 'my_filter');
var_dump($new_lines);
And your callback function would be :
function my_filter($line) {
$min = '2009-09-04';
$max = '2009-09-09';
if ($line >= $min && $line <= $max) {
return true;
} else {
return false;
}
}
And, the result :
array
4 => string '2009-09-04,SWF,0.177,99.90' (length=26)
5 => string '2009-09-05,SWF,0.177,99.90' (length=26)
6 => string '2009-09-06,SWF,0.177,99.90' (length=26)
7 => string '2009-09-07,SWF,0.177,99.90' (length=26)
8 => string '2009-09-08,SWF,0.177,99.90' (length=26)
Hope this helps ;-)
If your dates where not in the YYYY-MM-DD
format, or not at the beginning of each line, you'd have to explode
the lines, and use strtotime
(or do some custom parsing, depending on the format), and, then, compare timestamps.
But, in your case... No need for all that ;-)