Hi there,
Does any one know a Perl regular expresson to ignore specific string from a log file.
For example i want to use this simple unix command using perl regular expression

egrep -i -n "error|fatal" logfile.log |\egrep -v "user not found"

i.e. it should ignore log file entry "Error user not found" but at the same time if log file contains "error script fails" it should detect "error".

Thanks in advance.

maybe post a few lines of the logfile..?

Hi there,
Does any one know a Perl regular expresson to ignore specific string from a log file.
For example i want to use this simple unix command using perl regular expression

egrep -i -n "error|fatal" logfile.log |\egrep -v "user not found"

i.e. it should ignore log file entry "Error user not found" but at the same time if log file contains "error script fails" it should detect "error".

Thanks in advance.

You mean this??

if(/error script fails/i) {
     next if(/Error user not found/i);
}

here is the log file content

365:[2005-02-10 10:43:39,499][testapi][INFO ][Servlet.Engine.Transports : 252][service.BaseService] - ApplRef: null Error -NXFB=(8;701) user not found in database.
370:[2005-02-10 10:43:47,955][testapi][ERROR][Servlet.Engine.Transports : 41][OLDLOGGING] - - E - - - User does not have the
required access level for this application.

The first line should be ignored eventhough it contents sring "Error".
but the second line should raise a flag because it does not content string "user not found in database"
i believe it's clear now. I'm looking for regular expression to parse this kinda log file. i can simply use egrep and egrep-v but that's not the solution i cna use here.

How about just parsing for [ERROR]?

How about just parsing for [ERROR]?

if($line =~ /\[ERROR\]/) {
      print "It contains error\n";
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.