From: Rob Biedenharn Date: 2010-12-15T01:48:48+09:00 Subject: Re: Grep a string On Dec 14, 2010, at 11:20 AM, Rajesh M. wrote: > Peter Vandenabeele wrote in post #968289: >> On Tue, Dec 14, 2010 at 2:32 PM, Rajesh M. wrote: >>> 0 10 * * 0 sync; sync; reboot <---- regex should look for only sync; >>> For example in another system if the crontab entry is like: >>> 0 6 * * 0 shutdown -y -g0 -i6 >>> regular expression should only look for the string after digitals >>> 0 6 * >>> * 0, here it should look for shutdown -y -g0 -i6 >> >> If on the commandline, 'cut' may be useful. >> >> $ cat crontab | egrep '^[0-9\*]' >> 17 * * * * root cd / && run-parts --report /etc/cron.hourly >> 25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts >> --report /etc/cron.daily ) >> 47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts >> --report /etc/cron.weekly ) >> 52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts >> --report /etc/cron.monthly ) >> >> $ cat crontab | egrep '^[0-9\*]' | cut -f3- >> root cd / && run-parts --report /etc/cron.hourly >> root test -x /usr/sbin/anacron || ( cd / && run-parts --report >> /etc/cron.daily ) >> root test -x /usr/sbin/anacron || ( cd / && run-parts --report >> /etc/cron.weekly ) >> root test -x /usr/sbin/anacron || ( cd / && run-parts --report >> /etc/cron.monthly ) >> >> 'cut' splits by default on and there seem to be exactly 2 TAB's >> before the 'root' >> part (you can use $ od -ax crontab to check that in detail). >> >> HTH, >> >> Peter > > > > cat /tmp/cron.list | egrep '^[0-9\*]' > 00 01 * * 0 (sync ; sync ; sync ; /sbin/reboot) > 00 18 * * 6 (sync; sync; sync; /sbin/reboot) > > > Not sure it is still getting digits, what am doing wrong here? > > -- > Posted via http://www.ruby-forum.com/. > cat /tmp/cron.list | ruby -nle 'next if $_ =~ /^\s*#/; fields = $_.split(" ",6); puts fields.inspect;' Or: cat /tmp/cron.list | ruby -nle 'next unless $_ =~ /sync|reb|shut/; fields = $_.split(" ",6); puts fields.inspect;' Can you work with that? If not, then why do you keep asking on a Ruby list? -Rob Rob Biedenharn Rob@AgileConsultingLLC.com http://AgileConsultingLLC.com/ rab@GaslightSoftware.com http://GaslightSoftware.com/