list all scripts in crontab which contains the string "sqlplus"

Hi folks

I use a Solaris 10 box with Bash shell.

I have here a script (it works!) to list all scripts in crontab which contains the string "sqlplus":

for i in $(ls `crontab -l | grep -v '#' | awk '{ print $6 }' | grep -v '^$'`); do grep -l 'sqlplus' "$i"; done

Is there a more elegant solution? How would you do?

You could probably do the whole thing with awk but I think this is a little bit nicer:

grep -l sqlplus $( crontab -l | awk '/^#/d {print $6 }' )

edit: only thing is if you have no cron jobs it will grep from stdout so perhaps a redirect from null for this special case:

grep -l sqlplus $( crontab -l | awk '/^#/d {print $6 }' ) < /dev/null