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

"Schneider, Jim" <[email protected]>
Newsgroups gmane.editors.sed.user
Message-ID <1BAE7BA06260134CA211546087707A5912906D@scswpmail1.na.ds.ussco.com>
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
====================================================================
I realize I'm cheating here but 
crontab -l | grep -p -v 'Purge tables' > new.crontab

will do the trick.  The '-p' flag treats blocks of text separated by blank lines as a single unit.  The '-v' flag excludes that block of text.
After verifying new.crontab, move it into place.

I realize I'm suggesting unix commands in place of sed and don't intend to offend this group.

Jim Schneider

**********************************************************************
Information contained in this e-mail message and in any attachments thereto is confidential. If you are not the intended recipient, please destroy this message, delete any copies held on your systems, notify the sender immediately, and refrain from using or disclosing all or any part of its content to any other person.
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.