searching using regular expressions

Hi

I want to be able to use a regular expression which goes through a large txt file where all my Packages (around 100) are kept.
The objective is for the ruby script/regex to return the Package name and the tables and joins used.

CREATE OR REPLACE PACKAGE TEST
SELECT *
FROM
TABLE1
INNER JOIN TABLE2 ON TABLE1.ID = TABLE2.ID
LEFT JOIN  TABLE3 ON TABLE1.REF = TABLE3.REF
WHERE TABLE1.ID > 14


CREATE OR REPLACE PACKAGE TEST2
SELECT *
FROM
TABLE1a
INNER JOIN TABLE2a ON TABLE1a.ID = TABLE2a.ID
LEFT JOIN  TABLE3a ON TABLE1a.REF = TABLE3a.REF
LEFT JOIN  TABLE4  ON TABLE4.NAME = TABLE2a.NAME
WHERE TABLE4.NAME IN ('FRED','BRIAN')

etc etc


ouptut file would read as .......

CREATE OR REPLACE PACKAGE TEST
TABLE1
INNER JOIN TABLE2 ON TABLE1.ID = TABLE2.ID
LEFT JOIN  TABLE3 ON TABLE1.REF = TABLE3.REF

CREATE OR REPLACE PACKAGE TEST2
INNER JOIN TABLE2a ON TABLE1a.ID = TABLE2a.ID
LEFT JOIN  TABLE3a ON TABLE1a.REF = TABLE3a.REF
LEFT JOIN  TABLE4  ON TABLE4.NAME = TABLE2a.NAME

any help much appreciated.

Regards
PHIL SawyerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
Why does the output contain
TABLE1
but not
TABLE1a
?
0
PHIL SawyerAuthor Commented:
Sorry - my fault - it should.

Regards
0
ozoCommented:
while line = STDIN.gets
     unless line=~/SELECT|FROM|WHERE/
       puts line
     end
  end
0
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

PHIL SawyerAuthor Commented:
Thanks for that - one further question if I may....
I want to be able to include the select * from line only if a word follows the word "from" otherwise I do not want to include the line eg
select * from mytable - this is ok
select *
from
mytable where  etc - then I'm not interested in returning the lines select * & from
Regards
0
ozoCommented:
while line = STDIN.gets
     unless line=~/^\s*(WHERE.*)?(SELECT\s*\*\s*)?(FROM\s*)?$/i
       puts line
     end
  end
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PHIL SawyerAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Ruby

From novice to tech pro — start learning today.