Hi Charlie
Funny, this has been a popular one :)
Lets split up the regex:
$data =~ m/DHCPDISCOVER from\s*(.+?)\s*via eth0/;
'DHCPDISCOVER from' looks for the text Jorge said flagged the start of the
string
'\s*' absorbs (zero or more) whitespace characters, including
the newline
(...) makes the regex store this part of the match in $1
'.+?' matches at least one of any character. The ?
'non-greedy' modifier
makes it match a minimum number of times, but it will
have to match
enough so that the remainder of the regex succeeds
'\s*' zero or more whitespace characters
'via eth0' what Jorge said flagged the end of his string. So our
previous .+?
has to match up to 'via eth0' possible preceded by
whitespace
I should have explained the next line as well. Putting parentheses into a regex
makes perl store whatever was matched by the bracketed expression into built-in
variables $1, $2, ... You can even nest the brackets: the variables will be
assigned in the order of the open bracket within the regex.
HTH,
Rob
> -----Original Message-----
> From: Weaver, Charles [mailto:[EMAIL PROTECTED]]
> Sent: 05 September 2001 13:37
> To: 'Rob Dixon'
> Subject: RE: Parse file
>
>
> Hello, I know I was not the intended recipient of your help, but I copied
> the code and the text file to look at it and when I ran it, it worked. Much
> to my surprise. I am, obviously new to perl, and am having trouble parsing
> files. Could you either point me in the right direction or explain your
> line "$data =~ m/DHCPDISCOVER from\s*(.+?)\s*via eth0/;". Hell for that
> matter the line after needs some explanation. I think that somehow you are
> assigning the portion of the file you want to $1 and then assigning it to
> $data and printing $data out. Your help would be greatly appreciated.
>
> Charlie
>
> -----Original Message-----
> From: Rob Dixon [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, September 05, 2001 6:09 AM
> To: Jorge Goncalvez; [EMAIL PROTECTED]
> Subject: RE: Parse file
>
>
> Hi Jorge
>
> This does what you want, and I think is fairly straightforward. The line
> 'local
> $/' temporarily undefines the record separator for the scope of the
> enclosing
> block, so that the read on the next line pulls in all of the file. (I assume
> your files aren't any bigger than you showed us?)
>
> open FILE, "< file.txt" or die $!;
>
> my $data;
>
> {
> local $/;
> $data = <FILE>;
> }
>
> close FILE;
>
> $data =~ m/DHCPDISCOVER from\s*(.+?)\s*via eth0/;
> $data = $1;
>
> print "$data\n";
>
> Come back to me if there's anything you don't understand.
>
> Cheers,
>
> Rob
>
>
> > -----Original Message-----
> > From: Jorge Goncalvez [mailto:[EMAIL PROTECTED]]
> > Sent: 05 September 2001 10:49
> > To: [EMAIL PROTECTED]
> > Subject: Re:Parse file
> >
> >
> > Hi, I have a file which looks like :
> >
> > dhcpd : LOG_INFO : Internet Software Consortium DHCP Server 2.0
> > dhcpd : LOG_INFO : Copyright 1995, 1996, 1997, 1998, 1999 The
> > Internet Software
> > Consortium.
> > dhcpd : LOG_INFO : All rights reserved.
> > dhcpd : LOG_INFO :
> > dhcpd : LOG_INFO : Please contribute if you find this software useful.
> > dhcpd : LOG_INFO : For info, please visit
> http://www.isc.org/dhcp-contrib.html
> > dhcpd : LOG_INFO :
> > dhcpd : LOG_INFO : Listening on Socket/eth0/155.132.0.0
> > dhcpd : LOG_INFO : Sending on Socket/eth0/155.132.0.0
> > dhcpd : LOG_INFO : DHCPDISCOVER from
> > 52:41:53:20:c0:f6:c8:35:6c:80:c0:01:01:00:00:00 via eth0
> > dhcpd : LOG_ERR : Booting denied, no alcatel XID and the vendor class is
> empty
> > dhcpd : LOG_INFO : DHCPDISCOVER from
> > 52:41:53:20:b0:c0:d0:69:49:34:c1:01:01:00:00:00 via eth0
> > dhcpd : LOG_ERR : Booting denied, no alcatel XID and the vendor class is
> empty
> > LOG_INFO : cabs41.col.bsf.alcatel.fr: read request for /bootp/cygwin.bat:
> > success.
> >
> >
> > How can I extract what is betwwen DHCPDISCOVER from and via eth0?
> >
> > Thanks
> >
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
>
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]