Reputation: 3380
I have a text file with the following format
CREATE TABLE `a` (
.
.
);
CREATE TABLE `b` (
.
.
);
and so on and so on...
I want to extract individual tables and am trying with sed but it doesn't seem to work:
sed -n '/^CREATE\sTABLE\s`a`/,/^;$/p' file
This is unfortunately not providing the intended behavior. It is producing the entirety of the file instead of just the code block.
It should only grab one code block.
Found issue (dumb typo):
sed -n '/^CREATE\sTABLE\s`a`/,/;$/p' file
Upvotes: 0
Views: 61
Reputation: 729
With sed
and suppressing the last line by head -n -1
# sed -ne '/CREATE TABLE `b`/,/CREATE TABLE/p' tmp7|head -n -1
CREATE TABLE `b` (
.
.
);
Upvotes: 0
Reputation: 203254
$ awk -v RS= '$3=="`a`"' file
CREATE TABLE `a` (
.
.
);
$ awk -v RS= '$3=="`b`"' file
CREATE TABLE `b` (
.
.
);
If that's not what you need then edit your question to provide more truly representative sample input and the associated expected output.
Upvotes: 1