Home » SQL & PL/SQL » SQL & PL/SQL » Regular expression
Regular expression [message #327705] Tue, 17 June 2008 05:59 Go to next message
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 #327711 is a reply to message #327705] Tue, 17 June 2008 06:14 Go to previous messageGo to next message
Littlefoot
Messages: 21823
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
What is "a line above"? Above what? Where are these lines?

Are you, perhaps, looking for LAG and/or LEAD functions?
Re: Regular expression [message #327726 is a reply to message #327705] Tue, 17 June 2008 06:36 Go to previous messageGo to next message
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 #327729 is a reply to message #327726] Tue, 17 June 2008 06:55 Go to previous messageGo to next message
Littlefoot
Messages: 21823
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Quote:
the line above should also be found.

If you say so /forum/fa/3314/0/...

But I still have no idea where to search for these lines.
Re: Regular expression [message #327730 is a reply to message #327726] Tue, 17 June 2008 06:57 Go to previous messageGo to next message
Michel Cadot
Messages: 68733
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Anyway you should follow:
Quote:
Are you, perhaps, looking for LAG and/or LEAD functions?

Regards
Michel
Re: Regular expression [message #327738 is a reply to message #327726] Tue, 17 June 2008 07:18 Go to previous messageGo to next message
S.Rajaram
Messages: 1027
Registered: October 2006
Location: United Kingdom
Senior Member
Check this link. It might be of use to you.

http://www.orafaq.com/forum/m/308687/94420/?srch=external+table#msg_308687

Regards

Raj
Re: Regular expression [message #327742 is a reply to message #327729] Tue, 17 June 2008 07:27 Go to previous messageGo to next message
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 #327743 is a reply to message #327742] Tue, 17 June 2008 07:29 Go to previous messageGo to next message
Michel Cadot
Messages: 68733
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
In addition to external table + LEAD/LAG functions, you can also use awk.

Regards
Michel
Re: Regular expression [message #327967 is a reply to message #327742] Wed, 18 June 2008 08:15 Go to previous message
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-".
Previous Topic: SQL Tunning
Next Topic: How Many unique constraints can be allowed for a Table?
Goto Forum:
  


Current Time: Fri Feb 07 19:04:31 CST 2025