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

只谈情不闲聊 提交于 2019-12-22 20:45:14

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/12014275/how-do-i-add-a-comment-in-front-of-a-line-after-a-key-word-search-match

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!