Extracting data between two characters


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting data between two characters
# 8  
Old 01-25-2010
How about:
Code:
awk -F')' '{print $1}' RS='(' infile

This should extract all occurrences even text that is on multiple lines between parentheses.

---------- Post updated at 11:44 ---------- Previous update was at 11:29 ----------

This variation will present multiple line matches on a single line (may be desirable)
Code:
awk -F')' '{gsub(/\n/," ",$1);print $1}' RS='(' infile


Last edited by Scrutinizer; 01-25-2010 at 06:43 AM..
# 9  
Old 01-25-2010
Scrutinizer,

Maybe I'm missing something, with:
Code:
awk -F')' '{print $1}' RS='('

I get this as output:

Code:
$ cat file
abc1(opp1)aop
abc2(opp2)aop
abc3(opp3)aop
$ awk -F')' '{print $1}' RS='(' file
abc1
opp1
opp2
opp3
$

And idem with:

Code:
$ awk -F')' '{gsub(/\n/," ",$1);print $1}' RS='(' file
abc1
opp1
opp2
opp3
$

One approuch for multiple line matches on a single line:

Code:
awk -F"[()]" '{for(i=2;i<NF;i+=2){print $i}}'

# 10  
Old 01-25-2010
Franklin52, you are right:
These should work better:
Code:
awk -F')' 'FNR>1{print $1}' RS='(' infile

-and-
Code:
awk -F')' 'FNR>1{gsub(/\n/," ",$1);print $1}' RS='(' infile

# 11  
Old 01-25-2010
Quote:
Originally Posted by dinjo_jo
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.
Dinjo, thanks for the help. I was not able to make that work from the command line.

I am trying to do as much research on my but it can get a little confusing.


Thanks everyone that took the time to respond.

Much much appreciated.

Ted

Last edited by TedSD; 01-25-2010 at 10:45 PM..
# 12  
Old 01-26-2010
Quote:
Originally Posted by dinjo_jo
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.
Am sorry about that, I thought that you were giving the answer to the OP and not the hint.
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