Este forro perl faz o trabalho:
perl -0777 -nE 'say $1 while(/(\d{4}-\d\d-\d\d \d\d:\d\d:\d\d,\d+(?:(?!ORA-\d+)(?!\d{4}-\d\d-\d\d \d\d:\d\d:\d\d,\d+).)*ORA-\d+(?:(?!\d{4}-\d\d-\d\d \d\d:\d\d:\d\d,\d+).)*)/sg)' file.txt
Isso imprimirá o conteúdo do grupo 1 ( $1
) toda vez que ele for encontrado.
Opções:
-0777 : slurp mode
-n : add a loop around the script
-E : enable features ("say" in this case)
Regex:
/ : regex delimiter
( : start group 1
\d{4}-\d\d-\d\d \d\d:\d\d:\d\d,\d+ : regex for date
(?: : start non capture group
(?! : negative look ahead, make sure we don't have the following
ORA-\d+ : literally "ORA-" followed by digits
) : end lookahead
(?! : negative look ahead, make sure we don't have the following
\d{4}-\d\d-\d\d \d\d:\d\d:\d\d,\d+ : regex for date
) : end lookahead
. : any character
)* : non capture group is present 0 or more times
ORA-\d+ : literally "ORA-" followed by digits
(?: : start non capture group
(?! : negative look ahead, make sure we don't have the following
\d{4}-\d\d-\d\d \d\d:\d\d:\d\d,\d+ : regex for date
) : end lookahead
. : any character
)* : non capture group is present 0 or more times
) : end group 1, contents in "$1"
/sg : regex delimiter, s: single line, g: global
Exemplo de arquivo de entrada:
2017-11-29 23:51:46,013 (Foo.java:67) FATAL - foo.bar()-got exception
during load of zzz javax.persistence.PersistenceException:
org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614)
ORA-04031: unable to allocate 3896 bytes of shared
memory ("shared pool","selec t licensekey0_.ID as ID...","sga
heap(1,0)","kglsim object batch")
2017-11-29 23:51:46,013 (Foo.java:67) FATAL - foo.bar()-got exception
during load of zzz javax.persistence.PersistenceException:
org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614)
(NO ORA.....) unable to allocate 3896 bytes of shared
memory ("shared pool","selec t licensekey0_.ID as ID...","sga
heap(1,0)","kglsim object batch")
2017-11-29 23:51:46,013 (Foo.java:67) FATAL - foo.bar()-got exception
during load of zzz javax.persistence.PersistenceException:
org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614)
ORA-04031: unable to allocate 3896 bytes of shared
memory ("shared pool","selec t licensekey0_.ID as ID...","sga
heap(1,0)","kglsim object batch")
Resultado:
2017-11-29 23:51:46,013 (Foo.java:67) FATAL - foo.bar()-got exception
during load of zzz javax.persistence.PersistenceException:
org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614)
ORA-04031: unable to allocate 3896 bytes of shared
memory ("shared pool","selec t licensekey0_.ID as ID...","sga
heap(1,0)","kglsim object batch")
2017-11-29 23:51:46,013 (Foo.java:67) FATAL - foo.bar()-got exception
during load of zzz javax.persistence.PersistenceException:
org.hibernate.exception.GenericJDBCException: could not execute query
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614)
ORA-04031: unable to allocate 3896 bytes of shared
memory ("shared pool","selec t licensekey0_.ID as ID...","sga
heap(1,0)","kglsim object batch")
O segundo bloco não é exibido