gpt4 book ai didi

regex - 正则表达式 : Change syntax from perl to others with grep command

转载 作者:太空狗 更新时间:2023-10-29 11:03:41 24 4
gpt4 key购买 nike

我想从警报日志文件(在 Linux 上)中查找 Oracle 错误,但应该排除一些错误。

这是我使用的 perl 语法。

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

这会查找以“ORA-”开头的 Oracle 错误。但是应该排除 'ORA-01013' OR 'ORA-16957' 这两个错误

它适用于 grep -P 选项,但其他语法不起作用。

我想更改此语法以使用扩展正则表达式(-E 选项)或其他语法。

我必须将此命令应用于 Monitoring Solution。该解决方案看起来不支持 Perl 语法正则表达式。

示例输入

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

期望的输出

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

最佳答案

对于任何远程复杂的事情,你最好使用 awk 而不是 grep,因为 awk 允许复合条件,而不仅仅是正则表达式匹配:

$ 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

关于regex - 正则表达式 : Change syntax from perl to others with grep command,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37985512/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com