Problem in extracting the string between parenthesis


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Problem in extracting the string between parenthesis
# 1  
Old 03-16-2010
Bug Problem in extracting the string between parenthesis

Hi Team,

I am not able to extract string between parenthesis.I need to extract string between first parenthesis only.
Please find the sample data and code.
But the below my code is returning "DW_EFD_TXN_ID", "PRCS_DTE" & INITIAL 52428800 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT.
Kindly give some suggestion to extract the string DW_EFD_TXN_ID, PRCS_DTE alone.

Content:

ALTER TABLE "DWJR1"."TB_EF_DZT_CRDHLD_ACTY_DIM" ADD CONSTRAINT "PK_TB_EF_DZT_CRDHLD_ACTY_DIM" PRIMARY KEY ("DW_EFD_TXN_ID", "PRCS_DTE")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255
STORAGE(INITIAL 52428800 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
TABLESPACE "JR1D_BIC_INDEXES" ENABLE

Required Output :

DW_EFD_TXN_ID, PRCS_DTE

Sample Code :
Code:
cat temp | cut -d '(' -f 1 - | cut -d ')' -f 2 -

Thanks
Suriya Vignesh

Last edited by vbe; 03-17-2010 at 11:10 AM..
# 2  
Old 03-16-2010
It looks like you're just using the wrong fields...

Code:
cat blah
ALTER TABLE "DWJR1"."TB_EF_DZT_CRDHLD_ACTY_DIM" ADD CONSTRAINT "PK_TB_EF_DZT_CRDHLD_ACTY_DIM" PRIMARY KEY ("DW_EFD_TXN_ID", "PRCS_DTE") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 STORAGE(INITIAL 52428800 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "JR1D_BIC_INDEXES" ENABLE

jsmith:..ksh $ cat blah | cut -d'(' -f 2 | cut -d')' -f 1
"DW_EFD_TXN_ID", "PRCS_DTE"


Last edited by jsmithstl; 03-16-2010 at 08:22 PM.. Reason: added cat blah
# 3  
Old 03-17-2010
Code:
cat file| grep -Eo "\(.*\)" | sed 's/(//'|sed s'/)//'

# 4  
Old 03-17-2010
MySQL

See the following code.

Code:
egrep -o "([(].*?[)])" b | sed "s,[\(|\"|\)],,g"

The Output :

DW_EFD_TXN_ID, PRCS_DTE

---------- Post updated 03-17-10 at 00:03 ---------- Previous update was 03-16-10 at 23:57 ----------

Quote:
Originally Posted by murugaperumal
Code:
cat file| grep -Eo "\(.*\)" | sed 's/(//'|sed s'/)//'

hi murugaperumal why you are not removing the double quotes.
he wants the output without double quotes.

Last edited by ungalnanban; 03-17-2010 at 02:09 AM..
# 5  
Old 03-17-2010
Quote:
Originally Posted by murugaperumal
Code:
cat file| grep -Eo "\(.*\)" | sed 's/(//'|sed s'/)//'

Code:
grep -Eo "\(.*\)" file | sed 's/(//'|sed s'/)//'

Useless use of cat. And also it is not removing the double quotes.
# 6  
Old 03-17-2010
Try this ,

Code:
grep -Eo "\(.+\)" file | tr '\"|(|)' '\0'

# 7  
Old 03-17-2010
Bug

Quote:
Originally Posted by ungalnanban
See the following code.

Code:
egrep -o "([(].*?[)])" b | sed "s,[\(|\"|\)],,g"

The Output :

DW_EFD_TXN_ID, PRCS_DTE

---------- Post updated 03-17-10 at 00:03 ---------- Previous update was 03-16-10 at 23:57 ----------



hi murugaperumal why you are not removing the double quotes.
he wants the output without double quotes.
Hi Ungalnanban,

Thanks for your effort Smilie.
But i am getting the following error
Error:
Code:
egrep -o "([(].*?[)])" DWPRD14_DWAA1_PK_TB_C2_DYP_CNSL_PS_SCD_DIM.ddl | sed "s,[\(|\"|\)],,g"
egrep: illegal option -- o
usage: egrep [ -bchilnsv ] [ -e exp ] [ -f file ] [ strings ] [ file ] ...

But i have tried with following command,its working fine
Code:
egrep "([(].*?[)])" b| sed "s,[\(|\"|\)],,g" | cut -d ' ' -f 9-

The Output :

DW_EFD_TXN_ID, PRCS_DTE

Anyhow i would like to know why -o option is not working for me.

Please help me on this.

Last edited by vbe; 03-17-2010 at 11:13 AM.. Reason: code tags please!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extracting substring within string between 2 token within the string

Hello. First best wishes for everybody. here is the input file ("$INPUT1") contents : BASH_FUNC_message_begin_script%%=() { local -a L_ARRAY; BASH_FUNC_message_debug%%=() { local -a L_ARRAY; BASH_FUNC_message_end_script%%=() { local -a L_ARRAY; BASH_FUNC_message_error%%=() { local... (3 Replies)
Discussion started by: jcdole
3 Replies

2. Shell Programming and Scripting

extracting data from a string

Hi there, I have a bunch of vlan tagged network interfaces that are named as follows e1000g111000 e1000g99001 e1000g3456000 nge2002 where the 'e1000g' and 'nge' parts of the name are the driver, the red and blue bits above define the VLAN and the last digit on the end defines the... (3 Replies)
Discussion started by: rethink
3 Replies

3. Shell Programming and Scripting

Help on extracting portion of string

Hi Gurus, I've some sample of my log information as shown below. -> Processing ABCD123456 This is tp version 372.04.57 (release 700, unicode enabled) This is R3trans version 6.14 (release 700 - 05.03.09 - 08:28:00). unicode enabled version R3trans finished (0000). Warning: Parameter... (1 Reply)
Discussion started by: superHonda123
1 Replies

4. Shell Programming and Scripting

Extracting substring from string

Hi awk and sed gurus, Please help me in the following. I have the following entries in the file ABCDErules AbHDPrules ABCrules -- -- and other entries in the file. Now, I want to extract from the file that contain entries for *rules and process it separately. How can i do it... (6 Replies)
Discussion started by: sdosanjh
6 Replies

5. Shell Programming and Scripting

Extracting particular string in a file and storing matched string in output file

Hi , I have input file and i want to extract below strings <msisdn xmlns="">0492001956</ msisdn> => numaber inside brackets <resCode>3000</resCode> => 3000 needs to be extracted <resMessage>Request time getBalances_PSM.c(37): d out</resMessage></ns2:getBalancesResponse> => the word... (14 Replies)
Discussion started by: sushmab82
14 Replies

6. Shell Programming and Scripting

Help with extracting text from a string

I dont know if I am making any sense here. But I need to do something like this. I have a variable that contains result from the svnlook command on a post-commit hook script. test=`/usr/bin/svnlook changed $REPOS -r $REV | grep "^A.*index.html$" and I get test=A ... (18 Replies)
Discussion started by: kminkeller
18 Replies

7. Shell Programming and Scripting

Extracting String

I am trying to extract a hyperlink from a html document using awk. I have managed to output in the format... href="index.html"> where i would like it just to output index.html. Any ideas on how i would do this? Thanks (2 Replies)
Discussion started by: adpe
2 Replies

8. Shell Programming and Scripting

extracting a string

Hi All, I am writing a shell script for which I am stuck with an extraction part. I arrived till extraction of a path of file. Lets take an example. I now have a file which contains following one line: 2348/home/userid/mydir/any_num_dir/myfile.text Now I want to extract only... (2 Replies)
Discussion started by: start_shell
2 Replies

9. Shell Programming and Scripting

Extracting a string from one file and searching the same string in other files

Hi, Need to extract a string from one file and search the same in other files. Ex: I have file1 of hundred lines with no delimiters not even space. I have 3 more files. I should get 1 to 10 characters say substring from each line of file1 and search that string in rest of the files and get... (1 Reply)
Discussion started by: mohancrr
1 Replies

10. Shell Programming and Scripting

extracting from a string

How do I extract 5th to 10th characters of string as given below stored in a shell variable. "ab cd ef gh ij kl" How is cut to be used on this? Thanks for any help. (1 Reply)
Discussion started by: preetikate
1 Replies
Login or Register to Ask a Question