944,191 Members | Top Members by Rank

Ad:
  • Perl Discussion Thread
  • Unsolved
  • Views: 5354
  • Perl RSS
Jan 31st, 2005
0

Regular expression

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Nihar is offline Offline
2 posts
since Jan 2005
Jan 31st, 2005
0

Re: Regular expression

maybe post a few lines of the logfile..?
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Feb 6th, 2005
0

Re: Regular expression

Quote originally posted by Nihar ...
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??

Perl Syntax (Toggle Plain Text)
  1. if(/error script fails/i) {
  2. next if(/Error user not found/i);
  3. }
Reputation Points: 10
Solved Threads: 0
Light Poster
YUPAPA is offline Offline
42 posts
since Dec 2004
Feb 11th, 2005
0

Re: Regular expression

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Nihar is offline Offline
2 posts
since Jan 2005
Feb 18th, 2005
0

Re: Regular expression

How about just parsing for [ERROR]?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Schwallex is offline Offline
1 posts
since Feb 2005
Feb 18th, 2005
0

Re: Regular expression

Quote originally posted by Schwallex ...
How about just parsing for [ERROR]?
Perl Syntax (Toggle Plain Text)
  1. if($line =~ /\[ERROR\]/) {
  2. print "It contains error\n";
  3. }
Reputation Points: 10
Solved Threads: 0
Light Poster
YUPAPA is offline Offline
42 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Perl Forum Timeline: where to start with perl?
Next Thread in Perl Forum Timeline: Beginner question: need help importing tab-delimited file as perl hash





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC