printing data between 2 occurances of regexp


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting printing data between 2 occurances of regexp
# 1  
Old 02-24-2010
printing data between 2 occurances of regexp

Hi,

I an new to this forum and i need help with awk regex processing.
I am trying to print chunk of data between occurances of reg expression
for example:

regex
chunkofdata1
regexp
chunkofdata2
regexp

i want to print "chunkofdata1" to file1 , "chunkofdata2" to file2 .. and so on

i have tried :

Code:
 
awk '/regexp1/,/regexp1/'

but this only prints the line with matching regex
# 2  
Old 02-24-2010
Something like this??

Code:
awk '{ if (/regex/) { f++; } else { print >"file"f; } }' file

# 3  
Old 02-25-2010
yesss !!

thanks alot Smilie

---------- Post updated 02-25-10 at 11:11 AM ---------- Previous update was 02-24-10 at 02:07 PM ----------

one more thing though ...

i want to print some extra information with it too ...
for example ...

Code:
regexp1     someinfo
 
         heading 1
regex2
chunkofdata1
regexp2
chunkofdata2
regexp2

with "chunkofdata1" and "chunkofdata2", i also want "regexp1", "someinfo" and "heading1"
since they are headers which contain imp info which is required for further processing

---------- Post updated at 11:17 AM ---------- Previous update was at 11:11 AM ----------

sorry, ive posted my question with the previous reply .. i hope thats ok ...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Rta data needs regexp

Hi echo "rta=58.124001ms;100.000000;150.000000;0.000000" I required 58.12 and 0.00 i,e from first and last. I tried using : awk -F"rta=" '{print $2}' and last one awk -F";" '{print $4}' but unsuccessful. Thanks (5 Replies)
Discussion started by: ashokvpp
5 Replies

2. Shell Programming and Scripting

Matching the entries and printing data

Hi all, I have a file with Id which I want to compare it with other file to get the sequence of a particular id. File 1 with ID Q7L8J4 Q676U5 Q8NAA4 Q5TYW2 Q5SQ80 Q5VUR7 Q4UJ75 Q96IX9 Q7Z4T9 Q6NTF7 Q8IZP0 Q9NYB9 Q9P2A4 O14639 Q9ULW3 (5 Replies)
Discussion started by: manigrover
5 Replies

3. Shell Programming and Scripting

occurances

Hi, I have 2 files File 1 ABC XYZ MNO WER FDS CFG File 2 ABC_123456_234567 ABC_123456_234567 ABC_123456_234567 ABC_123456_234567 ABC_123456_234567 (1 Reply)
Discussion started by: Diya123
1 Replies

4. Shell Programming and Scripting

Printing another column using awk and input data

Hi, I have data of the following type, chr1 234 678 39 852 638 abcd 7895 chr1 526 326 33 887 965 kilj 5849 Now, I would like to have something like this chr1 234 678 39 852 638 abcd 7895 <a href="http://unix.com/thread=chr1:234-678">Link</a> chr1 526 326 33 887 965 kilj 5849 <a... (5 Replies)
Discussion started by: jacobs.smith
5 Replies

5. Shell Programming and Scripting

Extracting and printing data

Hi I have the following data : <Cell id="34A" ref="ds:/BTS:34/Cells/Cell:34A"/> <Cell id="34B" ref="ds:/BTS:34/Cells/Cell:34B"/> <Cell id="34C" ref="ds:/BTS:34/Cells/Cell:34C"/> I would like to print this data in the following format : BTS:34 Cell:34A.I'm... (9 Replies)
Discussion started by: Prega
9 Replies

6. UNIX for Dummies Questions & Answers

changing all occurances

how wouldi change all occurances of that to they regardless of the number of times it appears on a line? (2 Replies)
Discussion started by: trob
2 Replies

7. UNIX for Dummies Questions & Answers

replacing all occurances

How would i replace all occurreneces of Tim(ignoring the case) with Timithoy in the file "file1" and then save it to "newfile" (2 Replies)
Discussion started by: JamieMurry
2 Replies

8. UNIX for Dummies Questions & Answers

occurances

Hi, Anyone know how to do the following? :eek: I Have a file as follows: happygoluckypeoplearenotalwayshappy happyisawordthatisnotusedalot If the word "happy" is present MORE than once in EACH line, I want to delete the line, hence in the above case, the first line will be deleted. ... (8 Replies)
Discussion started by: dr_sabz
8 Replies

9. UNIX for Dummies Questions & Answers

print the line immediately after a regexp; but regexp is a sentence

Good Day, Im new to scripting especially awk and sed. I just would like to ask help from you guys about a sed command that prints the line immediately after a regexp, but not the line containing the regexp. sed -n '/regexp/{n;p;}' filename What if my regexp is 3 word or a sentence. Im... (3 Replies)
Discussion started by: ownins
3 Replies

10. Shell Programming and Scripting

AWK - printing certain fields when field order changes in data file

I'm hoping someone can help me on this. I have a data file that greatly simplified might look like this: sec;src;dst;proto 421;10.10.10.1;10.10.10.2;tcp 426;10.10.10.3;10.10.10.4;udp 442;10.10.10.5;10.10.10.6;tcp sec;src;fac;dst;proto 521;10.10.10.1;ab;10.10.10.2;tcp... (3 Replies)
Discussion started by: eric4
3 Replies
Login or Register to Ask a Question