How to use sed to remove a line from a cron file and also remove all commented lines directly above it
| Newsgroups | gmane.editors.sed.user |
|---|---|
| Message-ID | <620889240.986508.1341869449822.JavaMail.root@sz0115a.emeryville.ca.mail.comcast.net> |
I realize you can't just run sed on a cron file, but I need to run sed to delete the command and all commented lines directly above the removed line. Basically, for any text file like below, remove the line containing the pattern and any commented lines directly above it. In the text below, I want to remove every line from the line beginning with Purge through the line containing the pattern $BACKUPDIR/runBackup.sh . Any ideas? 55 10 * * * /opt/company/runThisCommand.sh # Purge tables and rebuild database indexes # The first five crontab fields are integer patterns that specify the following: # minute (0-59), # hour (0-23), # day of the month (1-31), # month of the year (1-12), # day of the week (0-6 with 0=Sunday). 45 22 * * * . /etc/profile; . $BACKUPDIR/runBackup.sh 0 1 * * * /opt/company/runAnotherCmd.sh [Non-text portions of this message have been removed]