Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 850
Han Gyo Jung Avatar asked Jan 21 '26 10:01

Han Gyo Jung


2 Answers

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
like image 123
Ed Morton Avatar answered Jan 23 '26 00:01

Ed Morton


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.

like image 43
Arijit Panda Avatar answered Jan 23 '26 01:01

Arijit Panda



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!