Need to pull matched string plus a few additional bytes
- From: PMiller@xxxxxxxxx (Phil Miller)
- Date: Fri, 27 Oct 2006 09:36:50 -0400
I am working on my very first program and have run into a bit of a
roadblock. I am trying to print a report of users who show up in an IIS
Log file. The good news is that the format of the userid is
WINDOWSDOMAIN\USERID. The bad news is that it is not always at the same
place in the IIS Log file due to some variable length fields that come
before it. Its location can vary left or right by about 10 bytes.
I read the IIS Log file in one line at a time. I have gotten far enough
that I can identify the lines with WINDOWSDOMAIN on it, but am stuck
there. The code $userid = substr($logfile_in, 33, 12); gets me close
but depending on the length of the date, the time or the IP address, it
is usually off by a few bytes. A sample of the input is below to
explain what I am talking about.
2006-10-23 12:08:47 24.32.35.123 WINDOWSDOMAIN\USERID 175.128.127.43 80
GET /itd/styles/main.css
2006-10-23 12:08:47 24.32.35.123 WINDOWSDOMAIN\USERID 175.128.127.43 80
GET /itd/styles/contents.aspx
2006-10-23 12:08:47 24.32.35.123 WINDOWSDOMAIN\USERID 175.128.127.43 80
GET /itd/styles/footer.aspx
Essentially what I need to do is find the WINDOWSDOMAIN on a line, and
write to a file the matched string plus \USERID data (up to the next
space). Does anyone have any suggestions? I'm thinking there must be
some very easy way to do it since Perl is made for this sort of thing.
I remember reading about some Perl built-in capability that would take a
scalar variable and parse it into an array based on a delimiter, but I
can't remember what it is. That would probably do it for me. But if
you know of a better way, I'm all ears.
Below is the code I am using.
# My first PERL program.
open USERIDOUT, ">userid.out.txt";
open IISLOG, "<ex061023.log";
$ctr = 0;
$hit_counter = 0;
$miss_counter = 0;
$logfile_in;
$userid;
while (<IISLOG>)
{
$logfile_in = $_;
if ( ($logfile_in =~ m/WINDOWSDOMAIN/i && $logfile_in =~
m/itd/i)
)
{
print "\n** Found success\n";
$hit_counter += 1;
$userid = substr($logfile_in, 33, 12);
# This is not correct but is somewhat close
print "\n", $userid;
}
else
{
print "Did not find success\n";
$miss_counter += 1;
}
}
print "\n Hit Counter = ", $hit_counter;
print "\n Miss Counter = ", $miss_counter;
print "\n Total Records Counter = ", $hit_counter + $miss_counter;
close USERIDOUT;
close IISLOG;
*****************************************************
Phil
Confidentiality Notice:
This e-mail and any attachments may contain confidential information intended solely for the use of the addressee. If the reader of this message is not the intended recipient, any distribution, copying, or use of this e-mail or its attachments is prohibited. If you received this message in error, please notify the sender immediately by e-mail and delete this message and any copies. Thank you.
- Follow-Ups:
- Re: Need to pull matched string plus a few additional bytes
- From: D. Bolliger
- Re: Need to pull matched string plus a few additional bytes
- From: Arnaldo Guzman
- Re: Need to pull matched string plus a few additional bytes
- Prev by Date: win32 services
- Next by Date: Re: win32 services
- Previous by thread: win32 services
- Next by thread: Re: Need to pull matched string plus a few additional bytes
- Index(es):
Relevant Pages
|