對不起,如果是重複。我有一個看起來像crontab項:如何在SED中留言作爲評論
* * * * * sleep 15;/etc/opt/wer.sh
1 * * * * /opt/sfm/qwe/as.sh
如何插入#上包含調用「as.sh」使用sed的行?
如何取消註釋?
對不起,如果是重複。我有一個看起來像crontab項:如何在SED中留言作爲評論
* * * * * sleep 15;/etc/opt/wer.sh
1 * * * * /opt/sfm/qwe/as.sh
如何插入#上包含調用「as.sh」使用sed的行?
如何取消註釋?
可以使用:
sed '/\/as.sh/s/^/#/'
其將與包含/as.sh
所有行評論的字符替換起始行零寬度的標記,如顯示在下面的例子:
pax> echo '
* * * * * sleep 15;/etc/opt/wer.sh
1 * * * * /opt/sfm/qwe/as.sh
' | sed '/\/as.sh/s/^/#/'
* * * * * sleep 15;/etc/opt/wer.sh
#1 * * * * /opt/sfm/qwe/as.sh
但是你需要記住一些事情。
cron
需要重新讀取它。如果您使用crontab
命令本身,則這是自動的,但如果您直接編輯文件,則可能必須向cron
發送信號。爲了擺脫標記的使用:
sed '/\/as.sh/s/^#//'
這是相反的操作,發現含有/as.sh
那些線條和家裏無所事事行開始替換任何#
字符。
要添加註釋:
sed -e "s/\(.*\)\(as.sh\)/\#\1\2/g"
要刪除評論:
sed -e "s/\(^#\)\(.*\)\(as.sh\)/\2\3/g"
用crontab -e修改當前用戶的crontab。