extracting part of file into another file
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 |
If the tables are separated by an empty line, this might work...
Code:
sed -n '/table50/,/^$/p' file.txt >file2.txt |
Thanks, I was able to get what i needed with that sed command, its new to me.
|
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. |
Quote:
|
That too, in Computing in general, there's usually more than one way to do it.
|
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. Sed and Vim are both related to "ed". |
All times are GMT -5. The time now is 02:19 PM. |