-
Fetch block of text in huge file
After a server crash all I have now is a large mysqldump-file containing some 500 databases.
I'm looking for a way to import just a few databases, one by one, on a new server. mysql itself can't do this, it's "all or nothing".
So I'm trying to grep / sed / awk / whatever a block from mysqldump.sql to a new file. Having tried a lot with no success, I now turn to you, the community
(I know I can import everything to mysql on some other server, then pull out the databases needed and use those dumps on production server, but A) it's not efficient and B) this thing happens now and then so it would be nice to find the perfect solution.)
So, in a file I want to catch everything between
CREATE DATABASE /*!32312 IF NOT EXISTS*/ $1
and the next
CREATE DATABASE
Any ideas?
In pingvino veritas!
-
... after having spent so many hours, and finally asking for help...
I read my own question, and finally realized the real problem - which was not catching a block of text but interpreting those " /*! " correctly.
So I simply search for everything between
<database_name>
and
"CREATE DATABASE"
Problem solved, thanks for listening!
Oh, and just in case someone is interrested, complete command:
sed -n /$db_name/,/CREATE\ DATABASE/p mysql_030812.sql > db_name.sql
In pingvino veritas!
-
Nice one X !
Linux is for those who can think and reason it out.
-
Thanks saikee!
Often when I'm stuck with a problem I find that formulating a question actually gives me the answer or at least point me in the right direction.
This is because then I have to think things through clearly, describing problem and actions exactly and in detail often reveals "mind mistakes".
As for my solution, I have to add it wasn't quite correct. Since I have given a false solution I'm now adding a correct one.
The database name exists in other places too, so I actually needed to find how to search for pattern "IF NOT EXISTS*/ `db_name`"
The '`' surrounding the databasename was the worst problem. Putting the whole sed command in quotes did the trick - escaping it did not help:
sed -n "/EXISTS\*\/\ \`db_name/,/CREATE\ DATABASE/p" mysql_090812.sql > db_name_090812.sql
In pingvino veritas!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|