Extract data between two parenthesi

Thanks Ravinder for quick reply.Thats work.

One more thing if i want to extract something based on paranthesis....can you help.

Input:
exp1:

CREATE TABLE
(
A,
B,
C 
)

o/p exp1:

A,
B,
C

exp2:

CREATE TABLE
(
A,
B,
C,
D,
E 
)

exp2 output:

A,
B,
C,
D,
E

This needs to extract all data between parenthesis

Thanks

i need to extract data between two parenthesis
My input:
CREATE TABLE ABC
(
A,
B,
C,
D
);

I want to extract those data in between the two parenthesis.
My output:

A,
B,
C,
D

It is not constant ,the columns always varies from number to number.

like

CREATE TABLE PQR
(
A,
B
);

O/P

A,
B









---------- Post updated at 01:05 AM ---------- Previous update was at 12:11 AM ----------

Thans for sharing this in Perl but i need it to be done in Unix

perl -07 -ne 'print (/\(\n(.+)\)/s)' raju2016.input

or

perl -07 -ne 'print (/\(\n([^)]+)/gs)' raju2016.input

If there might be multiple parenthesized sets of data in an input file and you want to extract all of the parenthesized segments, you could also try:

awk '/^[)]/{p = 0}p;/^[(]/{p=1}' file

As always, if you want to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk or nawk .

1 Like

What makes you think that perl is not available on your UNIX system? Have you tried it? Although perl is not required by the POSIX standards, it is available on most BSD, Linux, and UNIX systems.

Are we already discussing this here:- How to remove a char before a pattern?

Please do not duplicate questions into new threads.

Hi Don,

Can we do that in While loop.if i have a file which contain some pattern and i will check that pattern in file and if matches i want to get that content to output file.

Exp:Pattern.txt

PQR
ABC

So one pattern goes first and if matches it should grab the whole contents and write into output file.

(
A,
B,
C
)

AND ON 2ND INSTANCE ABC LIKE THIS I WANT TO RUN IN LOOP

This is the third thread the OP asks the same question. This thread is closed.