Hi ,
I have a SQL file with a set of CREATE OR REPALCE statements. There are always two sets for every object created. I need the first occurance of each of these statements...
Like for example...
#my_orig_file.sql
CREATE OR REPLACE view test1
as select sysdate from dual;
CREATE OR REPLACE view test2
as select sysdate from dual;
CREATE OR REPLACE view test11
as select sysdate from dual;
CREATE OR REPLACE view test12
as select sysdate from dual;
What I need is the resultant file should have
CREATE OR REPLACE view test1
CREATE OR REPLACE view test11
What I tried doing was as below
#get_the_lines.awk
{
if ( var==0 && /CREATE OR REPLACE VIEW/ ) { print ; var=1 }
else { var=0 }
}
and call it
PROMPT> nawk -f get_the_lines.awk my_orig_file.sql
The thinking is that, set a variable and match the string. So print the first occurance and ignore the next.
The script above is giving me all the occurances and not just 1st, 3rd, 5th etc...
Any ideas please.
Thanks.
I have a SQL file with a set of CREATE OR REPALCE statements. There are always two sets for every object created. I need the first occurance of each of these statements...
Like for example...
#my_orig_file.sql
CREATE OR REPLACE view test1
as select sysdate from dual;
CREATE OR REPLACE view test2
as select sysdate from dual;
CREATE OR REPLACE view test11
as select sysdate from dual;
CREATE OR REPLACE view test12
as select sysdate from dual;
What I need is the resultant file should have
CREATE OR REPLACE view test1
CREATE OR REPLACE view test11
What I tried doing was as below
#get_the_lines.awk
{
if ( var==0 && /CREATE OR REPLACE VIEW/ ) { print ; var=1 }
else { var=0 }
}
and call it
PROMPT> nawk -f get_the_lines.awk my_orig_file.sql
The thinking is that, set a variable and match the string. So print the first occurance and ignore the next.
The script above is giving me all the occurances and not just 1st, 3rd, 5th etc...
Any ideas please.
Thanks.