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 23 May 2001, at 8:44, 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.
> 

Do you *need* to use perl? awk can handle this without the fuss..

'BEGIN{ FS=" ";} { print "The program called by cron was ", $4; }'

would print the 4th field which is what you are looking for plus the 
text. This assumes that the subject line is just the word 'Cron'. If 
you have a variable Subject: line this isn't going to work. YMMV.

James Gibson
twistedhammer@example.com





Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links