Re: please advise help with regex
- From: gregory.machin@xxxxxxxxx (Gregory Machin)
- Date: Thu, 28 Sep 2006 13:22:24 +0200
i have been playing... will this work and wich is more efficient ?
/^([0-3][0-9]\-
#day -----|
(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s+ #month
|
\-(20)[0-9][0-9]\s+
#year till 2099 |
[0-9][0-9]\:
#hour |= date and time
[0-9][0-9]\:
#miniute |
[0-9][0-9]\:)
#hour -----|
((\.\d{3})?
#milliseconds
(\w\:)
#catagory ----- catagory
(\s+\w\:)
#severity ----- serverity
(\w\s+)
#host ----- host
(s+\d+\.\d+\.\d+\.\d+)
#ip ----- ip
(\#\d+/i)
#port ----- port
(\:\s+\s\w\s\w\:) #view
----- view
(\s+[:alpha:]/) #query
----- query
On 9/28/06, Rob Dixon <rob.dixon@xxxxxxx> wrote:
Gregory Machin wrote:
> Hi
> I need to parse the logs for my named server. i'm having difficulty
getting
> my mind around the regex to break the data up .. i want the break it up
and
> store it in a data base then maniptulate the data from there ...
> | date | time |catagory|severity|client |ip
> |port |view | |query
> |
> 28-Sep-2006 10:10:57.266update: info: client 192.168.1.170#33364: view
> internal: updating zone 'lan.linserv.co.za/IN': adding an RR at '
> greg.lan.linserv.co.za' A"
>
> any ideas ?
Hi Gregory
It looks like your data fields are separated by a colon and a space,
except for
the first three. Is there really nothing at all between the milliseconds
and the
'category' field?
Anyway, assuming the data I have is correct (it's difficult to tell with
the
wrapping that the various email systems apply) the code below should do
what you
want. It works by splitting on, as I said, colon and whitespace, and then
pulling off the first field and splitting it again into three based on the
contents of these fields' data. You also seem to want the client field
split
into 'client', IP address and port number, so I've pulled that field out
and
split it up as well.
Hope it helps,
Rob
use strict;
use warnings;
while (<DATA>) {
chomp;
my @data = split /:\s+/;
my $prefix = $data[0];
splice @data, 0, 1, $prefix =~ /(\S+)\s+([0-9:.]+)(.+)/;
my $client = $data[-4];
splice @data, -4, 1, $client =~ /[^\s#]+/g;
print "$_\n" foreach @data;
}
__DATA__
28-Sep-2006 10:10:57.266update: info: client 192.168.1.170#33364: view
internal:
updating zone 'lan.linserv.co.za/IN': adding an RR at '
greg.lan.linserv.co.za' A"
**OUTPUT**
28-Sep-2006
10:10:57.266
update
info
client
192.168.1.170
33364
view internal
updating zone 'lan.linserv.co.za/IN'
adding an RR at 'greg.lan.linserv.co.za' A"
--
To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx
For additional commands, e-mail: beginners-help@xxxxxxxx
<http://learn.perl.org/> <http://learn.perl.org/first-response>
--
Gregory Machin
gregory.machin@xxxxxxxxx
www.linuxpro.co.za
- Follow-Ups:
- Re: please advise help with regex
- From: nobull67@xxxxxxxxx
- Re: please advise help with regex
- References:
- please advise help with regex
- From: Gregory Machin
- Re: please advise help with regex
- From: Rob Dixon
- please advise help with regex
- Prev by Date: Re: [Perl Win32]PPM: about the blocking ports or sth
- Next by Date: NET::SFTP - How to close connections
- Previous by thread: Re: please advise help with regex
- Next by thread: Re: please advise help with regex
- Index(es):
Relevant Pages
|