Zend certified PHP/Magento developer

sed: return all lines between matching patterns and quit

I want to extract only the lines that will restore a specific table from a mysql backup file. The following works.

    zcat /mnt/backup/full-replication.gz | sed -n -e '/DROP TABLE.*`account_codes`/,/UNLOCK TABLES/p' > account_codes.sql

However, the backup file it 9GB in size, so I’d like to stop searching once the ending match has been found. So in the sed part of the above command I could add {p;q} instead of p at the end like this:

    zcat /mnt/backup/full-replication.gz | sed -n -e '/DROP TABLE.*`account_codes`/,/UNLOCK TABLES/{p;q}' > account_codes.sql

That stops, but after the “from” match, not the “to” match. Essentially the output is then only the first line of the whole block.

    DROP TABLE IF EXISTS `account_codes`;

How can I fix this so that the q command only takes effect at the end matching pattern?