How to select text within the second ()?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to select text within the second ()?
# 1  
Old 10-11-2010
How to select text within the second ()?

Hello,

Can someone advise me how to select the text within the second bracket of a string in shell script?

For example, the input file:
some message (string A) some message (string B) some message (string C) some message (string D) some message (string E)

The number of bracket is random and how to get Sting B only?

Thank you very much!
Hanul
# 2  
Old 10-11-2010
Hi.

Depending on your version of awk:
Code:
$ awk -F"[()]" '{print $4}' file1
string B

# 3  
Old 10-11-2010
couple of ways:

Code:
#  str="some message (string A) some message (string B) some message (string C) some message (string D) some message (string E)"

#  echo $str|nawk -F"[()]" '{print $3}'
string B

#  echo $str | sed 's/[^(]*([^(]*(\([^)]*\)).*/\1/'
string B

HTH
This User Gave Thanks to Tytalus For This Post:
# 4  
Old 10-11-2010
Thanks very much!!!
# 5  
Old 10-11-2010
Code:
ruby -F'[)(]' -ane 'print $F[3]' file

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Using grep to select specific patterns in text file?

How do I use grep to select words that start with I or O, end in box, and contain at least one letter in between them? the text file mailinfo.txt contains Inbox the Inbox Is a match box Doesn't match INBOX Outbox Outbox1 InbOX Ibox I box If the command works correctly it... (4 Replies)
Discussion started by: steezuschrist96
4 Replies

2. Shell Programming and Scripting

Select row from file and text

Hi all! I would like to solve a problem but I have no clue of how do it!I will be grateful if someone could help me! Briefly I have a big file like this: >ENSMUSG00000000204 | ENSMUST00000159637 GGCGAGGCTTACGCCATTTTACCTCAGCGAGCATTCATAAAGCTGCGAGCATTCATACAG >ENSMUSG00000000204 |... (3 Replies)
Discussion started by: giuliangiuseppe
3 Replies

3. Shell Programming and Scripting

Parse SQL text and only format first SELECT statement.

Hi Forum. Need your expertise on the following question. I have the following file which I would like to parse, find first block of SELECT statment and concatenate all input fields as 1 field (~ delimited): Old File: SELECT /*+ USE_HASH(CCOMM ICAR IMAP IAS IP IMAS IMPS IAP SPCA) */ ... (5 Replies)
Discussion started by: pchang
5 Replies

4. UNIX for Dummies Questions & Answers

How to randomly select lines from a text file

I have a text file with 1000 lines, I want to randomly select 200 lines from it and print them as output. How do I go about doing that? Thanks! (7 Replies)
Discussion started by: evelibertine
7 Replies

5. Shell Programming and Scripting

Like to select text in a From/To list

Hi I need help to configure AWK to find a string based From/To filed I have a table like this 0A00 - 0AFF Nuts 0B00 - 0BFF Bolt If I have in a program a value like "0B22" I wold like to get "Bolt" in return. List are in Hex Still try to learn AWK :) (3 Replies)
Discussion started by: Jotne
3 Replies

6. Shell Programming and Scripting

search & select text

hi people; from my file:... ... ... 101221-18:45:17 192.168.1.1 1.0 PortNodeModel ========================================================= Object Attribute Value ========================================================= SectorPort=3 switchport 20 SectorPort=1 switchport 10 SectorPort=2... (12 Replies)
Discussion started by: gc_sw
12 Replies

7. Shell Programming and Scripting

select some text from a test dependng on pattern

I have some absolute file location $INSTALL_BASEPATH/onereview-5.0/resources/commons-messages/commonmessages_default.properties $INSTALL_BASEPATH/onereview-5.0/orv-deploy/config-console.war/WEB-INF/classes/com/connectiva/configuration/console/resource/configurationBundle.properties I need to... (3 Replies)
Discussion started by: mnmonu
3 Replies

8. Shell Programming and Scripting

random select text file ranamed

i want to need script.. source.txt /home/user1/public_html/test3 /home/user90/public_html/test9 . . . /home/user650/public_html/test000 read source.txt and cd /home/user**/public_html/*** and there is 1.txt, 2txt ~~25.txt and select 6 text files randomly among the... (4 Replies)
Discussion started by: topic32428285
4 Replies

9. Shell Programming and Scripting

Select block of text around matching braces

Hi, I have several block of text that I need to select, however this text may be spread over several lines and contains the '{' and '}' within it. For e.g., ABC=100{ DEF = 200 { GHI, JKL } } #2nd Block 123 { 456{78,910}} }I am trying to figure out how to remove... (2 Replies)
Discussion started by: BootComp
2 Replies

10. UNIX for Dummies Questions & Answers

Select text within matching ( ) bracket

Hi, I am looking for a simple command to select text within a open bracket "(" and a matching close bracket ")" and output the within-bracket-text to a file. This function is similar to the common vi select a range of text with "(" to ")" but not sure how to run the same function in command... (4 Replies)
Discussion started by: cursive
4 Replies
Login or Register to Ask a Question