Extract data between two parenthesi

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Extract data between two parenthesi
# 1  
Old 02-20-2017
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:
Code:
CREATE TABLE
(
A,
B,
C 
)

o/p exp1:

Code:
A,
B,
C

exp2:

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

exp2 output:

Code:
A,
B,
C,
D,
E

This needs to extract all data between parenthesis

Thanks


Moderator's Comments:
Mod Comment Seriously! PLEASE use CODE tags as required by forum rules!

Last edited by RudiC; 02-20-2017 at 05:21 PM.. Reason: Added CODE tags.
# 2  
Old 02-20-2017
Code:
perl -07 -ne 'print (/\(\n(.+)\)/s)' raju2016.input

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


Last edited by Don Cragun; 02-21-2017 at 01:39 AM.. Reason: Remove part that applies to another thread.
# 3  
Old 02-21-2017
Extract data between two parenthesi

Code:
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

Moderator's Comments:
Mod Comment This post duplicates post #1 which was moved here along with a response from another thread. That response may solve the problem. Due to the incorrect, and confusing use of CODE tags in this post, you are encouraged to ignore this post and just look at post #1.


---------- 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

Last edited by Don Cragun; 02-21-2017 at 01:55 AM.. Reason: Note confusion after merging posts from another thread.
# 4  
Old 02-21-2017
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:
Code:
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.
This User Gave Thanks to Don Cragun For This Post:
# 5  
Old 02-21-2017
Quote:
Originally Posted by raju2016
... ... ...

---------- 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
Moderator's Comments:
Mod Comment Please create a new post when you respond to a post instead of editing an earlier post. Editing a post doesn't let people who are following your thread know that any change has been made. Add a post sends mail to everyone who is following your thread.

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.
# 6  
Old 02-21-2017
Are we already discussing this here:- How to remove a char before a pattern?

Please do not duplicate questions into new threads.
# 7  
Old 02-21-2017
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

Code:
PQR
ABC

So one pattern goes first and if matches it should grab the whole contents and write into output file.
Code:
(
A,
B,
C
)

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



Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 02-21-2017 at 10:36 AM.. Reason: Added CODE tags.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract header data from one file and combine it with data from another file

Hi, Great minds, I have some files, in fact header files, of CTD profiler, I tried a lot C programming, could not get output as I was expected, because my programming skills are very poor, finally, joined unix forum with the hope that, I may get what I want, from you people, Here I have attached... (17 Replies)
Discussion started by: nex_asp
17 Replies

2. Shell Programming and Scripting

Help with File Data Extract

Hello, Hope you are doing fine. I have been struggling with it for some time now and I would really appreciate your help. Following is file format: Currency,Name,Date, Term USD, ABC, 2011/11/11, T0, S1, S2, S3, S4 , , ,T1, 5.6, 2.3, 6.5, 4.5 , ... (5 Replies)
Discussion started by: srattani
5 Replies

3. Shell Programming and Scripting

Need Help with a Data Extract script

hi, i'am trying to write a shell program which takes a data element from one file(var/tmp/usr1/pools)and search that data element in a zipped file in archive location/usr01/archive/PSta*.Z). cat var/tmp/usr1/pools FC5173 FI5178 BE5221 FE5229 ST1604 ls /usr01/archive/PSta*.Z... (14 Replies)
Discussion started by: kmr023
14 Replies

4. Shell Programming and Scripting

help with data extract script

hi, i'am trying to write a script which takes a data element from one file and searches in a certain file path and after it finds it it redirects the file names to a new file...Now i have to pick the up the last modified file's Timestamp(MMDDYY) from the files collected for each data element. ... (2 Replies)
Discussion started by: kmr023
2 Replies

5. Shell Programming and Scripting

Script to extract data

Hi, Pleae find the attached files. I want to extract all the table names that has got * mark within its last column data. The doc file will give you a clear picture of what I am trying to do. Tables names in oval should be extracted in other file because it has got * mark in its last column data (5 Replies)
Discussion started by: db2cap
5 Replies

6. Shell Programming and Scripting

Extract specific data content from a long list of data

My input: Data name: ABC001 Data length: 1000 Detail info Data Direction Start_time End_time Length 1 forward 10 100 90 1 forward 15 200 185 2 reverse 50 500 450 Data name: XFG110 Data length: 100 Detail info Data Direction Start_time End_time Length 1 forward 50 100 50 ... (11 Replies)
Discussion started by: patrick87
11 Replies

7. Shell Programming and Scripting

Extract data based on match against one column data from a long list data

My input file: data_5 Ali 422 2.00E-45 102/253 140/253 24 data_3 Abu 202 60.00E-45 12/23 140/23 28 data_1 Ahmad 256 7.00E-45 120/235 140/235 22 data_4 Aman 365 8.00E-45 15/65 140/65 20 data_10 Jones 869 9.00E-45 65/253 140/253 18... (12 Replies)
Discussion started by: patrick87
12 Replies

8. Shell Programming and Scripting

how to extract the data ?

Hi, I'm trying to pick out a data field eg. from below. I need the required field as below but they are filled sometimes with weird chars like \-(. or watever. How can I accurately extract the 3rd field in shell? :confused: ID IDNO - REQUIRED FIELD ID 1447 - MAT620BR. ID 1452 -... (13 Replies)
Discussion started by: uxnoob
13 Replies

9. Shell Programming and Scripting

extract data from a data matrix with filter criteria

Here is what old matrix look like, IDs X1 X2 Y1 Y2 10914061 -0.364613333 -0.362922333 0.001691 -0.450094667 10855062 0.845956333 0.860396667 0.014440333 1.483899333... (7 Replies)
Discussion started by: ssshen
7 Replies

10. UNIX for Dummies Questions & Answers

Extract data correction???

Hi I have file "test.txt" i need to extract the data as below from this file. /home/cvs/gkc ->awk -v RS= '{print $(NF-2),$(NF-1),$NF}' test.txt Buildfile: build.xml Buildfile: build.xml Created dir: /dist/advance/2.0.4/20060926-0413 awk: The field -1 must be in the range 0 to 199. ... (6 Replies)
Discussion started by: gkrishnag
6 Replies
Login or Register to Ask a Question