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"; } }

In reply to Re: Greping File by gmargo
in thread Greping File by x-plicit

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.