Regular expression [message #327705] |
Tue, 17 June 2008 05:59  |
hristo
Messages: 258 Registered: May 2007
|
Senior Member |
|
|
Hi!
Im a newbie on reg exp. I want this:
If I find "TNS-" then the line above allso should be included and displayed. Ie, two lines will be returned.
I now how to catch the two lines, but not at the same time.
Regards
newbie
Hristo
|
|
|
|
Re: Regular expression [message #327726 is a reply to message #327705] |
Tue, 17 June 2008 06:36   |
hristo
Messages: 258 Registered: May 2007
|
Senior Member |
|
|
24-MAJ-2008 09:02:53 * service_update * db303 * 0
TNS-error XXXXXXxxxxxxx xxxxx xxxxxxxxx xxxx xx x
When the TNS is found, the line above should also be found.
Regards
Hristo
|
|
|
|
|
|
Re: Regular expression [message #327742 is a reply to message #327729] |
Tue, 17 June 2008 07:27   |
hristo
Messages: 258 Registered: May 2007
|
Senior Member |
|
|
Search through the listener.log.
Thanks for all your replies, but I dont want to create a function in Oracle (thats why I created this thread in the other group, not SQL/PL). I only want to use the regexp in a application called PowerGrep to search through the big logfiles.
Regards
Hristo
[Updated on: Tue, 17 June 2008 07:31] Report message to a moderator
|
|
|
|
Re: Regular expression [message #327967 is a reply to message #327742] |
Wed, 18 June 2008 08:15  |
wernerf
Messages: 1 Registered: April 2008
|
Junior Member |
|
|
Regular expressions in the first place were not designed to search across line boundaries, though some implementations allow to look for patterns like
".*\nTNS-".
But the most elegant way for your problem is to use awk, like someone already suggested: Here's a sample script:
BEGIN {flag=0}
flag > 0 && /^TNS-/ {print line; flag=0; next}
{line=$0; flag=1}
END; {}
If you process a file with this awk script, it will print all lines which are followed by a line beginning with "TNS-". I inserted the "flag" stuff in order to handle situations like having a "TNS-" in the first line or having 2 or more consecutive lines beginning with "TNS-".
|
|
|