From: Rob Biedenharn Date: 2010-12-15T23:39:32+09:00 Subject: Re: Grep a string On Dec 14, 2010, at 6:21 PM, Ryan Davis wrote: > > On Dec 14, 2010, at 07:21 , Rob Biedenharn wrote: > >> Well, you asked on a Ruby list so you're getting a Ruby answer from >> me. >> >> crontab -l | ruby -nle 'next if $_ =~ /^\s*#/; fields = $_.split(" >> ",6); puts fields.inspect;' > > Don't forget the -a flag! > > % ruby -h | grep -- -a > -a autosplit mode with -n or -p (splits $_ into $F) > -Fpattern split() pattern for autosplit (-a) > > so you can do something like: > > % ruby -nae 'next unless $_ =~ /^[\d\*]/; p $F' > crontab.envy.zenspider.com > ["*/5", "*", "*", "*", "*", "~/Work/p4/zss/src/scripts/dev/ > p4autotest.sh"] > ["*/5", "*", "*", "*", "*", "~/Work/p4/zss/src/scripts/dev/ > p4review.py"] > ["*/15", "*", "*", "*", "*", "/Volumes/Users/www/zenspider.com/bin/ > webupdate.sh"] > ["0", "*", "*", "*", "*", "(imap_cleanse", "&&", "imap_flag)", "&>", > "/dev/null"] > ["12", "*", "*", "*", "*", "cd", "~/Work/git/synchronizer", "&&", > "rake", "-s", "sync"] Except that I have $_.split(" ", 6) since there are 5 schedule parts and 1 command part, I want all the command to be left together as a single part. So my fields[-1] is effectively $F[5..-1]*' ' had I used the -a. Good to remind the list of the flag though. -Rob Rob Biedenharn Rob@AgileConsultingLLC.com http://AgileConsultingLLC.com/ rab@GaslightSoftware.com http://GaslightSoftware.com/