954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Regular expression

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.

Nihar
Newbie Poster
2 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

maybe post a few lines of the logfile..?

Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

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);
}
YUPAPA
Light Poster
42 posts since Dec 2004
Reputation Points: 10
Solved Threads: 0
 

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.

Nihar
Newbie Poster
2 posts since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

How about just parsing for [ERROR]?

Schwallex
Newbie Poster
1 post since Feb 2005
Reputation Points: 10
Solved Threads: 0
 
How about just parsing for [ERROR]?
if($line =~ /\[ERROR\]/) {
      print "It contains error\n";
}
YUPAPA
Light Poster
42 posts since Dec 2004
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You