How to copy a portion of big text files in linux?

Working with big mysql dump file.

I have my sqldump file with this command:

mysqldump –opt -Q -uUSERNAME -p DATABASENAME > /PATH/TO/DUMP.SQL

So it dump all my databases into a single file.

The problem is, when moving to new server I can’t use the same database name (restriction on database naming). So I need to filter the files by line numbers, meaning I want to cut and paste the file in the middle, but that won’t be possible in notepad or windows editor that I know because it will just eat the memory and the PC will just hang doing nothing.

After searching for ways, I got the following lines:

grep -n ‘^Mary’ poem.txt

So it will print out the line numbers where the condition occurs. I change it to:

grep -n ‘^USE’ poem.txt

so it just print out the start of each different databases. What’s next? So this the output:

10: USE `db1`;

3434: USE `db2`;

8996: USE `db3`;

9881: USE `db4`;

So I’m gonna need only db2, I need to know how many lines this database is made up of (8996-3434=5562).

The next command is using this:

grep -A5562 ‘USE `db2`;’ dump.sql >newfile.sql

What it will do is just find the line containing ‘USE `db2`;’ and then pick the next 5562 lines and save it to newfile.sql.

Then I use vi editor to change the database name, then use this line to restore it to new database (even vi editor get a little slow for editing file containing thousands of lines):

mysql -uUSERNAME -p NEWDBNAME < /PATH/TO/NEW/DUMP.SQL

Posted February 4th, 2008 by mightyhitter under Linux | 1 Comment »

 

TimeNet Access Number

If you suddenly need to get an internet access by what you got is only a telephone line, then these numbers (beside 1313) are quite useful:
Please be aware that if you dial up to an TIMENet access number that’s not within your local call charging zone, you may be billed for STD/ long distance […]

Posted February 4th, 2008 by mightyhitter under Internet | No Comments »

 

Automatic anonymous comments deletion

Looks like I’m getting hundreds of spam comments in any of my single blog. Let’s stop these dumb robots. I have modified latest MightySpamBlocker to automatically delete any auto-submitted comments.
Download MightySpamBlocker here.

Posted January 24th, 2008 by mightyhitter under Wordpress | No Comments »

 

Latest Wordpress and some database structure changes

I never knew that the latest Wordpress (maybe starting from 2.3.0) makes major changes to the database structure if not because of my latest plugin MightyAlbum. It  introduce new tables, something about taxanomy and ignore the post2cats table. Browsing the content of post tables, you will notice that the post category is […]

Posted January 20th, 2008 by mightyhitter under Wordpress | No Comments »

 

You get what you give?

That’s what many folks said, but I have a friend who think otherwise. “Don’t give. Nobody gonna give you anything when you need it most either,” he said, a little frustrated maybe.
No. Keep the faith. The one who are giving are not the people around you, but Him, the one and only. Give, help […]

Posted January 20th, 2008 by mightyhitter under Life | 2 Comments »

 

PSABox Alive!

Okay, I have my last project PSABox getting online today. If not because of the mother disaster some few months back, it should been living online since then. It was so wonderful this morning - so I started going through the codes, line by line, page by page looking for the SQL statements - […]

Posted January 19th, 2008 by mightyhitter under Google Adsense, Uncategorized | No Comments »

 

Free Wordpress Hosting for Malaysian Friends

A little updates…
Those who are planning to have their own Wordpress blog, but not ready for a serious hosting cost can contact me. Sorry, Malaysians only. The application is opened until further notice. More details here at gamb.us. I have some tutorials in Bahasa too, all about setting up your own .com domain and […]

Posted January 16th, 2008 by mightyhitter under Wordpress | No Comments »

 

Getting first things first..

No it’s not the end of this blog just yet. The data lost was just an accident (yes, saying so makes me feel better!)
Okay, so I got this blog running for a month or so with no updates at all. Been busy with daily jobs and another fun part-time activity - unit […]

Posted January 16th, 2008 by mightyhitter under Wordpress | No Comments »

 

Sh*t happens..

Yes it is, and it’s the bad one that I got
Loosing the data.. sounds stupid, but I have to face it. So here is the best copy of my backup files that I have, dated back to Mar 2007. It’s ugly, but it’s all that I got.
For those of my friends and […]

Posted December 6th, 2007 by mightyhitter under Uncategorized | No Comments »

 

Kontera’s March 2007 Giveaway

If you have not registered just yet with Kontera, here is a little motivation: they are giving a free Visa Gift Card for the March’s lucky winner. Easy requirements; have the Kontera’s tags to be live on your sites, and earn a minimum $60 at the end of March. Easy?

We will randomly select the […]

Posted March 6th, 2007 by mightyhitter under Kontera | No Comments »