I am writing a sed command that should uncomment an entry in crontab on sun Solaris 10.

I have tried 2 ways and they are working on Ubuntu but they didn't work on Sun Solaris 10; it returns sed: illegal option -- E crontab: can't open your crontab file.

crontab -l | sed -E '/#* *([^ ]+  *){5}[^ ]*run_all.sh/s/^#* *//' | crontab -

also :

crontab -l | sed '/#* *\([^ ][^ ]*  *\)\{5\}[^ ]*run_all.sh\.sh/s/^#* *//' | crontab -

shell on crontab looks like :

###15 00 * * * /bill/u01/WORK/ALARMS/run_all.sh > /bill/u01/WORK/ALARMS/`date +\%Y\%m\%d\%H\%M\%S`_RUN_ALL_PROCEDURE.log
  • Do you really need anything more complicated than '/run_all\.sh/ s/^##* *//'? in particular, I don't see any value in using capture groups within the address pattern – steeldriver Jul 27 '19 at 15:19

You probably shouldn't overcomplicate the regex. To remove any possible hashtags at the beginning of lines containing the string run_all.sh, you could do:

crontab -l | sed 's/^#*\(.*run_all\.sh\)/\1/' | crontab -

Unfortunately, I don't have a Solaris system at hand to test it.

  • thank you dear you helped me alot, what if want to lead run_all.sh with ###shell what should i change? – mashro3ak Jul 27 '19 at 16:50
  • 1
    You mean the reverse operation? Use 's/.*run_all\.sh/###&/' instead. The & is a shorthand for the matched regex in the replacement. – Freddy Jul 27 '19 at 17:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.