Hi there,
I have a file with few sql statements in it and am trying to:
1. Extract all the lines other than lines starting from "copy"
including the following "\p\g" using AWK
OR
2. Delete the lines starting from "copy " including the following
"\p\g"
Problem is that the copy statement is repeting quite a few times.
Here's the sample file: Here's the output I want"
create table demo( create table demo(
demo1 char(10), demo1 char(10),
demo2 char(20) demo2 char(20)
) )
with duplicates, with duplicates,
location = (ii_database), location = (ii_database),
security_audit=(table,norow) security_audit=(table,norow)
\p\g \p\g
copy demo ( set journaling on demo
demo1= varchar(0)tab, \p\g
demo2= varchar(0)nl, create table hello(
nl= d1) hello1 char(10),
from 'C:/demo.ing' hello2 char(20)
with row_estimate = 2 )
\p\g with duplicates,
set journaling on demo location = (ii_database),
\p\g security_audit=(table,norow)
create table hello( \p\g
hello1 char(10),
hello2 char(20)
)
with duplicates,
location = (ii_database),
security_audit=(table,norow)
\p\g
copy hello (
hello1= varchar(0)tab,
hello2= varchar(0)nl,
nl= d1)
from 'C:/hello.ing'
with row_estimate = 2
\p\g
Here's the script I wrote which is almost working by taking copy
statement out until the following "\p\g". But I want the following
"\p\g" out as well.
BEGIN {
state=0;
}
/^copy.*/ {
if (state==0) {
state = 1
}
}
/^\\p\\g/ {
if (state==1) {
state=0
}
}
{
if (state==0) {
print
}
}
Any ideas would be appreciated.
Thanks in advance.