Thanks, I learned something from that answer.
However, when I sent the original email, there were no blank lines in the text.
Those were inserted by something between my Comcast account and the users group.
I think cron doesn't allow blank lines.
Also, I am looking to remove the block of commented lines, if any, that are directly
above the specified pattern. In the example I gave it begins with "# Purge" but in general
it could be any commented line (or no line at all).
----- Original Message -----
From: "Jim Schneider" <[email protected]>
To: [email protected], [email protected]
Sent: Tuesday, July 10, 2012 7:49:15 AM
Subject: RE: How to use sed to remove a line from a cron file and also remove all 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
====================================================================
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.
[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.