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

Pattern Matching

Status
Not open for further replies.

bbonn

Technical User
Joined
Jun 13, 2003
Messages
7
Location
US
Hi,

I have a print file I need to parse out all of the resources. I am quite new to perl, but it looks like it will do the trick. I need to match a word such as FONTS, and then grab everything after the =, up to a certain point say a closed parens or something. Can anyone help get me started??

Thanks a lot,

 
Not the easiest way, just something quick I threw together.
I think:

Code:
open(PRINTFILE, "< /path/to/file");
my ($junk,$aftereq,$befpar,$junk1);
while(<PRINTFILE>){
  if($_ =~ /FONTS/){
     ($junk,$aftereq) = split(/=/,$_);
     ($befpar,$junk1) = split(/\)/,$aftereq);
  }

}

$befpar is your results you are looking for.


___________________________________
[morse]--... ...--[/morse], Eric.
 
the more general way to do it is

if /FONTS.*XX(pp)YY/){
my $befpar=$1;
}

XX and YY are the "bracketing" patterns, pp is the pattern of interest. "()" captures the POI as $1.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top