regex - Regular Expression to match two strings in AND condition -
i new regular expression, please kindly me on error scenario need use regex match 2 error messages (appearing in different lines, same paragraph) in , condition log file:
msg1 - error [com.company.util.ejb.timedbean] () failed processing loader
msg2 - java.lang.runtimeexception: message code:[sl] unknown.
basically, need match (msg1)&&(msg2), in case, (error...loader) appear in first line , (java...unknown) follow in next line. messages follow order. not programming in typical language here, put enterprise tool accepts regexp.
if possible, show me how make in or condition (msg1)||(msg2)?
matching 2 consecutive lines is, in theory, matter of putting 2 regular expressions end-to-end. purposes of illustration, let's you've got file named logfile.txt contains messages you're looking for. linux command line this:
pcregrep -m -o '^error\n*loader$\njava\n*unknown\.$\n' logfile.txt and print line pairs you're looking for. breaking down parts:
^errormatches word error @ beginning of line.\n*matches number of characters aren't line terminator.loader$matches word loader @ end of line.\nmatches newline character. (might different on windows.)java\n*unknown\.$\nmore of same.
but... , big problem... tool handles regular expression must capable of doing multi-line matches, , capability must turned on. (that's -m command line option pcregrep enables.) many regexp tools, such plain grep on many systems, can't multiline searches. may out of luck.
Comments
Post a Comment