Hi,
i want to extract the 'CREATE INDEX' or 'CREATE UNIQUE INDEX' statements from a ddl file and output each match to a separate file. i was looking around the net but couldn�t find anything.
a possible sed-script could be:
sed -n '/CREATE[A-Za-z ]*INDEX*/,/COMMIT/p' filename.ddl
but i couldn�t find out how to output each match to a separate file. every CREATE-statement should go to its own file, while the filename is the name of the index.
Looking for a program to extract SQL statements is like looking for a programming language to print the letter 'A'. You're probably not going to find someone who had the exact same problem as you and solved it the exact same way...
-- TABLE001
CREATE UNIQUE INDEX ATABL001
ON TABLE001
(COLUMN1 ASC,
COLUMN2 ASC,
COLUMN3 ASC,
COLUMN4 ASC);
COMMIT;
CREATE INDEX BTABL001
ON TABLE001
(COLUMN3 ASC,
COLUMN4 ASC);
COMMIT;
CREATE INDEX CTABL001
ON TABLE001
(COLUMN3 ASC);
COMMIT;
-- TABLE002
CREATE UNIQUE INDEX ATABL002
ON TABLE002
(COLUMN1 ASC,
COLUMN2 ASC,);
COMMIT;
...
every single create index statement should go in its separate file e.g. index ATABL001 to ATABL001.ddl, BTABL001 to BTABL001.ddl, ... i mean the whole statement to the semicolon or the commit...
The difference is that gawk/nawk have close. Open too many files at once in awk and you can hit its limit -- and that can be pretty small on some systems!
Not all awk, especially not on "true" UNIXes where shell commands usually don't have any non-POSIX options or features. They'd rather add a 'nawk' than risk breaking vanilla awk's backwards compatibility in someone's 30-year-old shell script. In Solaris, nawk is available under the silly path of /usr/xpg4/bin/awk...
Linux/GNU usually has nothing but gawk. awk is just a symlink. Things like this can occasionally make testing UNIX scripts on Linux difficult -- features that seem so obvious they should be everywhere turn out to be missing...