in reply to Greping File
Here's some very simple regular expressions to get you started.
#!/usr/bin/perl use strict; use warnings; use diagnostics; my $msg = <<'MSGEND'; <msg time='2009-10-14T05:46:42.580+00:00' org_id='oracle' comp_id='tns +lsnr' type='UNKNOWN' level='16' host_id='mtdb_a' host_addr='UNKNOWN' +version='1'> <txt>14-OCT-2009 05:46:42 * (CONNECT_DATA=(SID=fgs)(CID= +(PROGRAM=sqlplus@mtdb)(HOST=mtdb_a)(USER=root))) * (ADDRESS=(PROTOCOL +=tcp)(HOST=10.60.4.2)(PORT=34898)) * establish * fgs * 0 </txt> </msg +> MSGEND print "msg: $msg\n"; # Isolate content of <txt> tags if ($msg =~ m{<txt>(.*)</txt>}) { my $txt = $1; print "txt: $txt\n"; # Find the date if ($txt =~ /(\d{2}-\w+-\d{4})\s+(\d{2}:\d{2}:\d{2})/) { my ($date, $time) = ($1, $2); print "date: $date\n"; print "time: $time\n"; } # Find the host (IP address, not name) if ($txt =~ /HOST=([\d\.]+)/) { my $host = $1; print "host: $host\n"; } }
|
|---|