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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing a text file 1

Status
Not open for further replies.

castout

Programmer
Jan 22, 2002
23
US
How would I search for a specific string that appears between two other specific strings? For example, given the following text I want the number that the first "ghi" refers to, so I need to find the "ghi" that comes after "abc" but before "pqr". I want to make sure I get the 789 instead of the 234.

abc123
def456
ghi789
jkl012
mno345
pqr678
def901
ghi234
jkl567
 
$first_string = 'abc';
$last_string = 'pqr';
$search_string = 'ghi';
while(<>){
next if /$first_string/o;
last if /$last_string/o;
print if /$search_string/o;
}
Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top