Han Gyo Jung
Han Gyo Jung

Reputation: 33

Regular Expression : Change syntax from perl to others with grep command

I want to find Oracle Error from the alert log file(on Linux) but some errors should be excluded.

Here is what I'm using which is perl syntax.

grep -P '.*^ORA-(?!.*(01013|16957))' alert_SID.log

This find the Oracle errors begining with 'ORA-'. But two errors that 'ORA-01013' OR 'ORA-16957' should be excluded

It works with grep -P option but other syntax doesn't work.

I'd like to change this syntax to work with extended-regexp(-E option) or others.

I have to apply this command to Monitoring Solution. The solution looks not support Perl syntax regular expression.

Sample Input

Sat Mar 28 14:18:13 2015

ORA-01013: user requested cancel of current operation

Sat Mar 28 15:04:59 2015

ORA-01013: user requested cancel of current operation

Mon Mar 30 11:25:32 2015

ORA-01722: invalid number

ORA-1142 signalled during: ALTER DATABASE END BACKUP...

Thu Apr 02 01:59:38 2015

Wed Apr 08 15:49:52 2015

DW00 started with pid=1412, OS id=25801, wid=1, job SYS.SYS_EXPORT_TABLE_01

ORA-00604: error occurred at recursive SQL level 3

ORA-28336: cannot encrypt SYS owned objects

Fri Apr 10 22:14:31 2015

ORA-16957: SQL Analyze time limit interrupt

Fri Apr 10 22:14:47 2015

ORA-16957: SQL Analyze time limit interrupt

Desired Output

ORA-01722: invalid number

ORA-1142 signalled during: ALTER DATABASE END BACKUP...

ORA-00604: error occurred at recursive SQL level 3

ORA-28336: cannot encrypt SYS owned objects

Upvotes: 3

Views: 319

Answers (3)

xxfelixxx
xxfelixxx

Reputation: 6592

I would use the -v flag to filter out the unwanted lines, after first finding all of the ORA- lines.

The -E flag enables the or construct using a pipe |.

 $ grep 'ORA-' logfile | grep -Ev "ORA-01013|ORA-16957"

 ORA-01722: invalid number
 ORA-1142 signalled during: ALTER DATABASE END BACKUP...
 ORA-00604: error occurred at recursive SQL level 3
 ORA-28336: cannot encrypt SYS owned objects

man grep

-E, --extended-regexp
     Interpret PATTERN as an extended regular expression

-v, --invert-match
     Invert the sense of matching, to select non-matching lines.

Upvotes: 1

Arijit Panda
Arijit Panda

Reputation: 1665

Try this command for your problem

grep -P 'ORA-\d+' alert_SID.log

or you can modify your output using bellow command

grep -o -P  'ORA-\d+.*' alert_SID.log

So you can try any one depending on your choice.

Hope this will work for you.

Upvotes: 1

Ed Morton
Ed Morton

Reputation: 203229

For anything remotely complicated you're better off using awk than grep since awk allows compound conditions, not just regexp matching:

$ awk '/ORA-/ && !/ORA-(01013|16957)/' file
ORA-01722: invalid number
ORA-1142 signalled during: ALTER DATABASE END BACKUP...
ORA-00604: error occurred at recursive SQL level 3
ORA-28336: cannot encrypt SYS owned objects

Upvotes: 2

Related Questions