You can use:
sed '/\/as.sh/s/^/#/'
which will replace the start-line zero-width marker with a comment character for all lines containing /as.sh
, as shown in the following example:
pax> echo '
* * * * * sleep 15;/etc/opt/wer.sh
1 * * * * /opt/sfm/qwe/as.sh
' | sed '/\/as.sh/s/^/#/'
* * * * * sleep 15;/etc/opt/wer.sh
#1 * * * * /opt/sfm/qwe/as.sh
But you need to keep in mind a couple of things.
- It's usually not enough to just change the file, you also need to notify
cron
that it needs to re-read it. This is automatic if you use the crontab
command itself but you may have to send a signal to cron
if you're editing the file directly.
- It's not always a good idea to turn scripts loose on important system files. Make sure you know what you're doing and don't trust any old codger on the net (including me). Test it thoroughly.
To get rid of the marker, use:
sed '/\/as.sh/s/^#//'
This is the opposite operation, it finds those lines containing /as.sh
and substitute any #
character at the start of the line with nothing.