I am trying to find the first occurrance of a date string in several
different files in order to re-write all of today's entries back into the
existing log file after taking out all the old entries to be archived.   (I
also realize lots of folks have done this and I'm sure come up with much
easier ways to do it.)  In our case each log entry is three lines long, only
the first line has the date in it.

I would like to use the same script for each file, however the date format
is slightly different in one of them.  In some files the date will have a
leading zero, in others it will not.
It can be:
    Wed Apr  3  or  Wed Apr 03

What I've written so far....

@ARGV = ("$logfile");                # prime the diamond operator
$¬I = ".bak";                        # write $logfile.bak for backup
while (<>) {
  if  ($todayfound eq "y") {         # IF today's date has already been
found
    print;                           # write to ARGVOUT, the new logfile
                                     # date format varies.
                                     # Usually:            Tue Apr   2
                                     # could also be:      Tue Apr  02
                                     # IF today's date found for first
time...
  } elsif (m/($weekday\s)($month\s+)(0?$day)/o) {
    $todayfound="y";                 # change flag
    print;                           # write to ARGVOUT, the new logfile
  } else {                           # IF we have not reached today's date
    print LOGCOPY;                   # write the line to the logcopy file
    s#.*\n##;                        # erase the line in ARGVOUT, the new
logfile
  }
}

My results so far.....
If I leave out the (0?$day)it does correctly find the first line with
$weekday and $month.  When I add in the last argument it never finds the
lines in question.    I really do need an argument for the date in order to
make sure I'm finding the correct Wednesday in April, etc.  Can somebody
tell me what I've done wrong? Any suggestions on better ways to do this are
also appreciated as I am definitely a novice.

Thanks!

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to