I have a huge MySQL backup file (from mysqldump) with the tables in alphabetical order. My restore failed and I want to pick up where I left off with the next table in the backup file. (I have corrected the problem, this isn't really a question about MySQL restores, etc.)
What I would like to do is take my backup file, e.g.
backup.sql and trim-off the beginning of the file until I see this line:
-- Table structure for `mytable`
Then everything after that will end up in my result file, say
backup-secondhalf.sql. This is somewhat complicated by the fact that the file is bzip2-compressed, but that shouldn't be too big of a deal.
I think I can do it like this:
$ bunzip2 -c backup.sql.bz2 | grep --text --byte-offset --only-matching -e '--Table structure for table `mytable`' -m 1
This will give me the byte-offset in the file that I want to trim up to. Then:
$ bunzip2 -c backup.sql.bz2 | dd skip=[number from above] | bzip2 -c > backup-secondhalf.sql.bz2
Unfortunately, this requires me to run bunzip2 on the file twice and read-through all those bytes twice.
Is there a way to do this all at once?
I'm not sure my sed-fu is strong enough to do a "delete all lines until regular expression, then let the rest of the file through" expression.
This is on Debian Linux, so I have GNU tools available.