perl toggle operator for extracting one table from mysql dump file

We did it with a nifty one liner perl command that uses the TOGGLE operator.

zcat fast.dmp.12082014_13_03.sql.gz |perl -ne 'if (/CREATE TABLE `budget`/../UNLOCK/ ) {print $_; }' > budget.1208.sql

This looks for lines in the dump between lines that match the green and yellow highlighted words ( which happen to be the separators we want )

We wanted to be able to rename our table so we could load it in the current schema as the live table so we added a substitution before printing like this:

zcat fast.dmp.12082014_13_03.sql.gz |perl -ne 'if (/CREATE TABLE `budget`/../UNLOCK/ ) {$_=~s/budget/budget_1210/; print $_; }' > budget.1208.sql

Good thing to have in your toolkit..

This entry was posted in Uncategorized. Bookmark the permalink.