This is the message file that I need to be parse.
<#|2014 Jul 29 16:20:20|INFO|JAVA_TEST_1.0.0|sun.java.jsf.managedbean +.AuthenticationMgr|DEFAULT|Login successful for user 'usr0001'|APPLIC +ATION USER|#> <#|2014 Jul 29 16:26:08|INFO|JAVA_TEST_1.0.0|sun.java.jsf.managedbean. +AuthenticationMgr|DEFAULT|Login successful for user 'usr0005'|APPLICA +TION USER|#> <#|2014 Jul 28 16:20:55|INFO|JAVA_TEST_1.0.0|sun.java.jsf.managedbean +.AuthenticationMgr|DEFAULT|Login successful for user 'usr0006'|APPLIC +ATION USER|#> <#|2014 Jul 28 16:22:44|INFO|JAVA_TEST_1.0.0|sun.java.jsf.managedbean. +user.UserRoleMgr|DEFAULT|Assigned roles for user 'usr0002' were modif +ied by user 'usr0006'|APPLICATION USER|#>
I have this configuration file where i put the search words so that i can decide what kind of event it is. cat EventType.conf
Application Error::Error Succesful Authorization::User Logged Succesfully Failed Authorization::User logon failed/unsuccesful
This is the perl script which reads the message file and checks with the Configuration file and returns the event name such as Succesful Authorization.
/usr/bin/perl /dir/perl/test.pl ${infile} ${outfile} cat test.pl #!/usr/bin/perl $dir="/dir"; $infile = $ARGV[0]; $outfile = $ARGV[1]; $configfile="$dir/conf/EventType.conf"; open(FILE, $infile) or die("Could not open $infile."); $/ = "#>\n"; $\ = "\n"; open(OUTFILE, ">", $outfile) or die("Could not open $outfile."); for $line (<FILE>) { # chomp($line); #split each line into fields and process @Line = split (/\|/, $line); #Check ETYPE and change EOUTCOME if ($Line[2] eq 'INFO') { $Line[5] = "INFO"; } elsif ($Line[2] eq 'ERROR') { $Line[5] = "ERROR"; } #Check EMSG and create new field next to it open CONFIG, $configfile or die "Could not open $configfile... + $!"; for $configLine (<CONFIG>) { chomp($configLine); @configLineItems = split /::/, $configLine; for $checkItem (@configLineItems) { if ("$Line[6]" =~ $checkItem) { $Line[8] = $configLineItems[0]; } else { $Line[8] = "Other Application Event" +; } } } #Write output print OUTFILE "|", $Line[1], "|", $Line[2], "|", $Line[3], "|" +, $Line[4], "|", $Line[5], "|", $Line[6], "|", $Line[8], "|", $Line[7 +],"|" ; close CONFIG; } close (FILE); close (OUTFILE);
Help needed on how efficiently I can use the Regex or grep in perl so that i can extract those values .and It is not one search word that is compared with the message ,it can be multiple words. "Login, succesful" are sought against the value being passed in $Line6 which is a event message. Thanks

In reply to Regex perl grep usage string match comparison by justinkala

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.