Extract the whole set if a pattern matches

Hi,

I have to extract the whole set if a pattern matches.i have a file called input.txt

input.txt
------------

 CREATE TABLE ABC
(
A,
B,
C
);
CREATE TABLE XYZ
(
X,
Y,
Z,
P,
Q
);

Now i have another file called table.txt which has an entry

Table.txt
----------

 XYZ

so now if XYZ matches the string in Input.txt then i need to grab it into a different file called output.txt.As XYZ maches the pattern which is in input.txt and need to push to output.txt

output.txt
----------

CREATE TABLE XYZ
(
X,
Y,
Z,
P,
Q
);

for better match we can include the whole string like CREATE TABLE XYZ

Try (untested)

awk 'NR==FNR {T[$1]; next} {for (t in T) if ($0 ~ t) print}' RS=";" ORS=";" table.txt input.txt
Hi Rudi,The code is working but i need to pass the pattern which is in Table.txt in  loop.So in the Table.txt file may conatin multiple patterns.so i need to process those one by one and  write into output file.So pattern will go to input file and match the pattern and write into output file.

Exp:
Table.txt

XYZ
ABC

oUTPUT.TXT
------------------
CREATE TABLE ABC
(
A,
B,
C
);
CREATE TABLE XYZ
(
X,
Y,
Z,
P,
Q
);

awk 'NR==FNR {T[$0]; next} {for (t in T) if ($0 ~ t) printf "%s;\n", $0}' table.txt RS=";"  input.txt

@Rudi:This is not working.i want to pass one record of Table.txt and search for that pattern and get the whole set from Input.txt and store into output.txt.

So in 1st instance i want to pass XYZ and look for that match in input.txt and then i need to do some transformationand later store into output.txt.

Same way the next record from table.txt is ABC and i need to pass that to Input .txt and do transformation and append that to output.txt.

i think we need to pass those with while loop/ for loop and get processed.

Well, it IS working, to the specs in posts#1 and #3. It gives exactly the desired / posted output.
If you need sth. else, start over and post a decent specification with requirements, input, and output samples.

And, as always, in addition to RudiC's already raised points: WHAT IS NOT WORKING, FOR CHRISSAKES??

If you are ill and visit a doctor: do you tell him your exact symptoms or just "it hurts"?

Show us what you did, what your input was, what your output was and how it differed from the expected output. Otherwise this is going to be a trade of "it works", "no, it doesn't", "yes, it does", "no, it doesn't", ... ad libitum ad nauseam.

Please take note: if you can't be bothered to tell us exactly what you want and how our suggestions fail (in other words: invest effort into your question) we won't be bothered to invest any effort in answering these question of yours. This here is give and take - and right now you are taking without giving.

bakunin