Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to look for 2 regex and print all preciding data

Status
Not open for further replies.
Jun 3, 2007
84
US
Hello everyone,

I am hoping someone can shed some light/point me in the right direction. I am trying to figure out how to search for the 1st occurrences of two strings and once they are found print all previous data.

Below is some sample data which I would be working with, any pointers etc would be greatly appreciated as I don't even know how to get that started.

Right now what I am doing is having to run matches on each line that I want to match and print on.

Code:
Sender: 123

Recipient:  aaa

Date: 2009/03/04

Time: 08:20:01

Operator: test

Subject: test01

Content: data data

Subject: RE: test

Content: data2 data

Additional: additional data

what I would like to do is find the first occurrence of Subject: followed by the first occurrence of Content: and print all data prior to the 1st Content: match.

desired output below:

Code:
Sender: 123

Recipient:  aaa

Date: 2009/03/04

Time: 08:20:01

Operator: test

Subject: test01
 
As your script reads the file, push each line onto the end of an array; when the keyword you're looking for is found, then the array contains all the lines read so far from the file.

Cuvou.com | My personal homepage
Code:
perl -e '$|=$i=1;print" oo\n<|>\n_|_";x:sleep$|;print"\b",$i++%2?"/":"_";goto x;'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top