in reply to Re: Process mail logs
in thread Process mail logs

Ok I think I have pieced together a solution but would appreciate one last ( hopefully ) piece of wisdom.

the host section of the log can look like any of the following examples

blah blah H=(10.21.32.43) [192.168.8.34] blah blah blah H=([10.21.32.43]) [192.168.8.34] blah blah blah H=mailsrvr.mail.com [192.168.8.34] blah

The data I want to assign is the number in the square brackets i.e. 192.168.8.34

How would I go about pattern matching to extract this i.e ip address in square brackets after space following initial text following H=

Many Thanks, Steve

Replies are listed 'Best First'.
Re^3: Process mail logs
by GrandFather (Saint) on Aug 13, 2012 at 22:59 UTC

    If you plan on using Perl for more than a day or two I strongly recommend you read through the regular expression documentation provided with Perl (see perlretut, perlre and perlreref). Perl is strong on text processing and a large chunk of that comes from using regular expressions so understanding Perl's regular expression is important to writing good Perl code.

    For this particular match you could make it more or less fussy (like mathing the () part or not). A somewhat non-fussy match would be /H=[^[]* \[ ([^\]]+) \]/x. Note the use of the x flag to allow white space in the expression so it's easier to see the various moving parts.

    True laziness is hard work

      Thank you very much for the help

      I have been reading the regex docs as I go but its difficult without experience to know what an efficient way to do these things is

      Again, Many Thanks, Steve