Mailing List Archive

Support open source code!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: REGEXP in perl questiion



On Wed, May 23, 2001 at 08:44:31AM -0000, Jean-Christian Imbeault wrote:
> Ok, I admint it's lazy but could someone give me a regular expression in 
> Perl that would do the following? (I've tried for the last hour but I'm not 
> very good at regular expressions it seems).
> 
> I have strings like the following:
> 
> Subject: Cron <root@example.com> /root/AdminScripts/NSH.sh
> Subject: Cron <root@example.com> /usr/bin/rsync -avzr --delete 
> /home/httpd/html/top40/* 10.0.1.53:/home/httpd/html/
> 
> I want to extract the name of the program that cron started, without the 
> switches if any.
> 
> I've tried this but it's greedy and doesn't extarct *just* the prog name but 
> also the switches ... I tought the " .*?" would cause lazy expansion but 
> it's not working as I had hoped.
> 
> if ( $_ =~ /^Subject: /) {
>   if ($_ =~ "Cron") {
>     $CRON_EMAIL = 1;
>     /^.*<.*> (/.*) *?.*$/;
		#this should work assuming there aren't any slashes after the 
      # the program name
		$PROGNAME =~ s/.*\/([^\s]+)\s.*/$1/;
>     $PROGNAME = $1;
>     print "The program called by cron was $PROGNAME\n";
>   }
> }
> 
> _________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
> 
> -----------------------------------------------------------------------
> Next Technical Meeting:  Sat, May 12 13:30- 
> Next Nomikai Meeting:    Fri, June (TBA) 19:30- Tengu Tokyo Eki Mae
> -----------------------------------------------------------------------
> more info: http://www.tlug.gr.jp           Sponsor: Global Online Japan


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links