Extracting data between two characters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting data between two characters
# 1  
Old 01-25-2010
Extracting data between two characters

From the command line how would I extract data in file that was contained between parenthesis "()"? Awk or Grep?

Thanks in advance

Ted
# 2  
Old 01-25-2010
The answer lies somewhere here.

echo "abc(opp)aop" | sed -n 's/(.*)//p'
# 3  
Old 01-25-2010
Quote:
Originally Posted by dinjo_jo
The answer lies somewhere here.

echo "abc(opp)aop" | sed -n 's/(.*)//p'
This will give output abcaop
and I think the request is other way around content within brackets

Code:
echo "abc(opp)aop" | sed "s/.*(\(.*\)).*/\1/

# 4  
Old 01-25-2010
With awk:
Code:
echo "abc(opp)aop" | awk -F"[()]" '{print $2}'

# 5  
Old 01-25-2010
Code:
echo "abc(opp)aop" | awk -F"(" '{print $2}' | awk -F")" '{print $1}'

or
Code:
echo "abc(opp)aop" |cut -d"(" -f2 | cut -d")" -f1


Last edited by Franklin52; 01-25-2010 at 05:41 AM.. Reason: Please use code tags!
# 6  
Old 01-25-2010
I never said my code is correct i said the answer lies somewhere here and i wanted the OP to try out on his own.
# 7  
Old 01-25-2010
Quote:
Originally Posted by ThobiasVakayil
Code:
echo "abc(opp)aop" | awk -F"(" '{print $2}' | awk -F")" '{print $1}'

or
Code:
echo "abc(opp)aop" |cut -d"(" -f2 | cut -d")" -f1

These solutions should do the job too, but not at the most efficient way.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Extracting range of characters if pattern matches

Im trying compare values between files and if they match I want to extract some characters in between those values for many files. They are in two directories and have the name filename but one ends in .enr. They look like this. cat bat.1.enr name,start,end bat.1,231, 234 and another... (5 Replies)
Discussion started by: verse123
5 Replies

2. Shell Programming and Scripting

Extracting characters and storing in some variable

eg: ./myProgram.sh filename.cpp I want to remove the :".cpp" extension from the filename.cpp expected output: filename (3 Replies)
Discussion started by: umesh314
3 Replies

3. UNIX for Dummies Questions & Answers

[Solved] Extracting all characters from a string

I want to extract the string TC from the string TC10, the string can have any characters out of . I used the following code but didnt get the right output. Please guide nuc=match(val,/*/) seq=substr(val,RSTART,RLENGTH) ---------- Post updated at 09:40 PM ---------- Previous update was... (0 Replies)
Discussion started by: newbie83
0 Replies

4. UNIX for Dummies Questions & Answers

Extracting data from file

I am trying to compare the data in lines 3 & 5 to see if they match up to the '-S570' (see first code set, all proprietary information has been removed from code set) spawn telnet Trying ... Connected to CA-LOS1234-ASE-S570.cl . Escape character is '^]'. CA-LOS1234-ASE-S570 Username: ... (1 Reply)
Discussion started by: slipshft
1 Replies

5. Shell Programming and Scripting

extracting data

I have a txt file of the following format >ab_ qwerty >rt_ hfjkil >Ty2 hglashglkasghkf; >P2 aklhfklflkkgfgkfl >ui_ vnllkdskkkffkfkkf >we32 vksksjksj;lslsf'sk's's .... ..... I want to split this big file based on the header (>) (5 Replies)
Discussion started by: Lucky Ali
5 Replies

6. Shell Programming and Scripting

Extracting specific lines of data from a file and related lines of data based on a grep value range?

Hi, I have one file, say file 1, that has data like below where 19900107 is the date, 19900107 12 144 129 0.7380047 19900108 12 168 129 0.3149017 19900109 12 192 129 3.2766666E-02 ... (3 Replies)
Discussion started by: Wynner
3 Replies

7. Shell Programming and Scripting

Extracting specific characters from a text file

I'm extremely new to scripting and linux in general, so please bear with me. The class I'm taking gives virtually no instruction at all, and so I'm trying to learn everything off the web. Anyway, I'm trying to extract characters that follow after a specific pattern ( '<B><FONT FACE="Arial">' ) but... (3 Replies)
Discussion started by: livos23
3 Replies

8. UNIX for Dummies Questions & Answers

Advice on extracting special characters from a DB2 table to a file in the UNIX ENV

need some advice on the following situation. I have a DB2 table which has a varchar Column. This varchar column can have special characters like ©, ®, ™ . When I extract from this table to a sequential file for this varchar column I am only able to get © and ® . To Get the ™... (1 Reply)
Discussion started by: cosec
1 Replies

9. UNIX for Dummies Questions & Answers

extracting few characters from a file

i want to extract few characters from a file based on a special character like || how to do it suggestions please (4 Replies)
Discussion started by: trichyselva
4 Replies

10. Shell Programming and Scripting

extracting usernames with at least 4 characters

Hi, i want to use grep to extract users with at least 4 characters in their username, i've tried who | grep \{4,\} but thats not working!!!!!! Thanks (4 Replies)
Discussion started by: c19h28O2
4 Replies
Login or Register to Ask a Question