Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I need some help with extracting some data from one file and put in another file.
Basically I have an sql file that has bunch of tables and data. and looks something like this:
CREATE TABLE `table1` ...
(table structure here)
(inserts data here)
CREATE TABLE `table1` ...
(table structure here)
(inserts data here)
CREATE TABLE `table3` ...
(table structure here)
(inserts data here)
and goes on for about 100 tables.. Im trying to figure out out to extract a specific table and put into a separate file.
For example, if i wanted to copy table50 to anther file, what would be the steps to find what line table 50 starts, and what line table 51 starts, as the ending point of table 50, and then put those lines into another file.
Any help would be appreciated. thanks
You can take a copy in vim and just delete preceding/succeeding lines if it's a one-off.
You can also use a combination of head and tail to do it if you know the line nums.
Yet another way in vim is to use:
1G
:/table50/,/^$/w extract
The "1G" just moves the cursor before the table (by going to line 1), so it may not be necessary. If you need to look at the sql script to determine what the table is called anyway, you don't need to exit vim (or view) to do the extraction.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.