With only one line from a logfile to work with, I have to do a little
guessing about format, but if all lines are formatted like that one, and if
days always have a two digit format, and if a lot of other assumptions, This
snippet does what you are looking to do:


my ($mon, $mday) = (localtime(time))[4, 3];

my @monarray = qw{Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec};

($mon, $mday) = ($monarray[$mon], (sprintf "%02d", $mday));

open (infile, "c:/blah/logfile.txt") || die "$!\n";  # open logfile

#now create a new logfile:
open (outfile, ">c:/blah/${mon}-${mday}_newfile.txt") || die "$!\n";


foreach (<infile>) {            #process the full log
                print outfile "$_" if (substr($_, 0, 6) eq "${mon}-${mday}");
                }


That is only going to work if you are searching for current day's entries.
If you need to search for yesterday's entries, or take input for how many
days etc. you'll have to work on the date searched for, but I might
recommend that you look at the Date::Calc module if you have much more than
a very simple date evaluation.

Does this answer the several questions you asked?

Of course, there is more than one way to do it.

Steve H.

-----Original Message-----
From: Corey Epps [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, August 15, 2001 2:55 PM
To: [EMAIL PROTECTED]
Subject: question from beginner


I'm trying to access log files on different Novell Servers.  Path is
<servername>\sys\arcserve.6\nwagent.txt

Here is the problem and why I'm trying to do this with Perl.  The log
file is extensive, and is sorted by date.

Example line:
Aug-14 20:11:42  Job request from <SERVERNAME> @ <IP ADDRESS>(NetWare
Server)

This is the first line of the log from the last night.  This is where I
want to start grabbing lines and appending them to another log.  I've
tried using the localtime function to determine the date and pipe it to
a new variable that will read similar to "Aug-14" to begin my search of
the file (nwagent.txt) with.  I'm beginning to get stuck there, then I'm
not sure how to open and read the file looking for and appending
everything (entire line) that matches that string.

Thanks in advance for any help or direction that can be given.


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


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

Reply via email to