mila002 mila002 - 3 months ago 19
Linux Question

Using sed to replace text with spaces and slashes

I'm trying to replace an entry in Crontab (RedHat) with sign #.
I tried sed command like this

sed -i 's|35 15 * * * /tmp/vii/ >/dev/null 2>&1|#|g' /var/spool/cron/root

but it doesn't work. Any ideas?


Don't try to edit crontab files directly, use crontab tools instead!!

You could use:

crontab -l

to dump actual crontab list.

crontab -l | sed '/^/# /'

... or more finely:

crontab -l | sed '/^35 \+15.*^/# /'

to pre-edit crontab list and see on terminal sed command result


crontab -l | sed '/^/# /' | crontab

to replace actual crontab list, once everything are ok.

But warn!

wrong Command | crontab

will erase completely your crontab list!!