Searching between dates

Hello people,
I have a file containing dated entries. Is there a way to search between dates? for example, in a file <file.text> with entries

04-jul-2005 login: pty0 xxxxxx xxxxxx
09-jul-2005 logout pty34 xxxxxx xxxxxx
11-aug-2005 arp port17 xxxxxx xxxxxx
30-sep-2005 awk line14 xxxxxx xxxxxx

In that format.

I want to search between july 9 and sep 30.

I have tried all tricks, no dice (so far). Any assistance will be appreciated

ruby -nle 'puts $_ if Time.local($_.split(/-| ./).reverse).between?(Time.local(5,7,9),Time.local(5,9,30))'

It gives a syntax error.

touch -t 200507090000.00 tempStartDateFile
touch -t 200509302359.59 tempEndDateFile

find $directory -name * -newer tempStartDateFile ! -newer tempEndDateFile

That last solution assumes that I am searching for files within a directory. Actually, what I am doing is searching between different entries within a single file.

Lots of ways to do it, easy if you have the Date::Manip perl module, but without you could put the following code in a file (make it executable). and run it with the input text file as the argument.

Assumes all lines are of the format in your original post and there are no leading spaces on the lines.

#!/usr/bin/perl
%months = (
  jul => 7,
  aug => 8,
  sep => 9
);

while (<>)
{
  @a = split('-');

  if ( $months{$a[1]} == 8 ||
       ($months{$a[1]} == 7 && $a[0] >= 9) ||
       ($months{$a[1]} == 9 && $a[0] <= 30)
     )
  {
    print;
  }
}

Umm... actually, I have entries from January to december, and dating since 2003. :o

#!/usr/bin/perl
%months = (
  jul => 7,
  aug => 8,
  sep => 9
);

while (<>)
{
  @a = split('\s+');
  @b = split('-',$a[0]);

  next if ($b[2] != 2005);

  if ( $months{$b[1]} == 8 ||
       ($months{$b[1]} == 7 && $b[0] >= 9) ||
       ($months{$b[1]} == 9 && $b[0] <= 30)
     )
  {
    print;
  }
}

Somehow I get the feeling that this will only work for a search between the three months (Jul, Aug and Sep). I need to get something that can search between any of the dates present in the file. I'll see if I can modify this one to suit my purpose.

It will search between july the 9 and september the 30th, which is what you specified in your original post ...

If you want something a lot more generic then I would suggest looking at one of the many more generic data manipulation posts on this bbs or install the Date::Manip perl module. and do this:

#!/usr/local/bin/perl
use Date::Manip;

$start="09-jul-2005";
$end="30-sep-2005";

while (<>)
{
  @a = split('\s+');
  print if ( (Date_Cmp($a[0],$start) >= 0) &&
             (Date_Cmp($a[0],$end) <= 0) );
}