nawk '/CREATE DATABASE \/\*\!32312 IF NOT EXISTS\*\/ \`%DB-NAME%\`/,$0 ~ /CREATE DATABASE/ && $0 !~ /%DB-NAME%/' DUMPFILE > DUMP_DB
Example:
nawk '/CREATE DATABASE \/\*\!32312 IF NOT EXISTS\*\/ \`meine_db\`/,$0 ~ /CREATE DATABASE/ && $0 !~ /meine_zweite_db/' full_dump.sql > meine_db_extract.sql
.. and for TABLES:
nawk '/DROP TABLE IF EXISTS `%TABLENAME%`/,/UNLOCK TABLES/' DUMP_DB > DUMP_TABLE
- Tags
- bash