Hey There,
You should be able to do this with vi (assumming your EDITOR environment variable is set to vi).
First, check out this article on how to "really" insert control characters into your scripts (like ^H backspace rather than a ^ symbol followed by a capital H):
http://linuxshellaccount.blogspot.com/2007/10/how-to-really-represent-control.html
Then, you should be able to do something to the effect of this (I set up a user crontab file with some bogus information just to show you how this works (Note that the basic trick to passing actual control characters to a command or in a script is to type ctl-V followed by the, let's say, return key to generate the ^M, etc). Since you need to run two commands to edit, I put them in a subshell () so that they would both execute and feed through the pipe:
$ crontab -l # DO NOT EDIT THIS FILE - edit the master and reinstall. # (/tmp/crontab.Y8BaFrkEZY installed on Wed Jan 7 21:26:33 2009) # (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $) 0 23 * * * /usr/bin/echo 0 23 * * * /usr/bin/watchdog 0 23 * * * /usr/bin/true 0 23 * * * /usr/bin/true
mgolvach@tlaum-pc1 ~ $ (echo ^[:g/watchdog/s/^/#/^[:wq!^M)|crontab -e Vim: Warning: Input is not from a terminal crontab: installing new crontab
mgolvach@tlaum-pc1 ~ $ crontab -l # DO NOT EDIT THIS FILE - edit the master and reinstall. # (/tmp/crontab.eQFF4ejmGJ installed on Wed Jan 7 21:26:47 2009) # (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $) 0 23 * * * /usr/bin/echo #0 23 * * * /usr/bin/watchdog 0 23 * * * /usr/bin/true 0 23 * * * /usr/bin/true
mgolvach@tlaum-pc1 ~ $ (echo ^[:g/watchdog/s/^#//^[:wq!^M)|crontab -e Vim: Warning: Input is not from a terminal crontab: installing new crontab
mgolvach@tlaum-pc1 ~ $ crontab -l # DO NOT EDIT THIS FILE - edit the master and reinstall. # (/tmp/crontab.y4rIj2VKQz installed on Wed Jan 7 21:27:04 2009) # (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $) 0 23 * * * /usr/bin/echo 0 23 * * * /usr/bin/watchdog 0 23 * * * /usr/bin/true 0 23 * * * /usr/bin/true
Best wishes,
If I can be of any extra help explaining, please let me know.
Mike