How to use sed to remove a line from a cron file and also remove all commented lines directly above it

[email protected]
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]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.