dave
dave

Reputation: 306

How do I add a comment (#) in front of a line after a key word search match

I have a crontab file contains many database names such as

10 06 1 * *   script  DEVE_DB1 
10 06 1 * *   script  TEST_DB1 
10 06 1 * *   script  PROD_DB1 
....

I would like to add a comment, # , in front of TEST_DB1 in the entire file so that my cron job will not run all TEST_DB1 jobs.

I found the following script on this site, sed -e '/TEST_DB1/, s/^/#/'

but I get an error:

sed: 0602-404 Function /TEST_DB1/, s/^/## / cannot be parsed.

Any suggestions would be greatly appreciated.

Upvotes: 3

Views: 5614

Answers (1)

Jonathan Leffler
Jonathan Leffler

Reputation: 754420

Lose the comma (the space is optional):

sed -e '/TEST_DB1/s/^/#/'

Given the start /TEST_DB1/,, sed would be expecting to find the second address in a range, such as a number, $, or another pattern. The s doesn't fit any of these constructs, hence the error.

Upvotes: 9

Related Questions