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<#|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|#>
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.Application Error::Error Succesful Authorization::User Logged Succesfully Failed Authorization::User logon failed/unsuccesful
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/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);
In reply to Regex perl grep usage string match comparison by justinkala
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |