Sed操作crontab的行
我想使用Sed操作crontab的行,sed,cron,crontab,Sed,Cron,Crontab,我想使用sed从我的crontab文件中删除一行。首先,我将用户的crontab保存在文件text.txt中。那么我想删除这一行: */5 * * * * svn update /root/tamainut/schedule/generico.sh && sh /root/tamainut/schedule/generico.sh 我想问题在于角色,但我迷路了。我试过: sed '*/5 * * * * svn update \/root\/tamainut\/schedule
sed
从我的crontab文件中删除一行。首先,我将用户的crontab保存在文件text.txt
中。那么我想删除这一行:
*/5 * * * * svn update /root/tamainut/schedule/generico.sh && sh /root/tamainut/schedule/generico.sh
我想问题在于角色,但我迷路了。我试过:
sed '*/5 * * * * svn update \/root\/tamainut\/schedule\/generico.sh && sh \/root\/tamainut\/schedule\/generico.sh/d' text.txt
sed: -e expresión #1, carácter 1: unknown command: `*'
我试过:
sed '*/5 * * * * svn update \/root\/tamainut\/schedule\/generico.sh && sh \/root\/tamainut\/schedule\/generico.sh/d' text.txt
sed: -e expresión #1, carácter 1: unknown command: `*'
sed '\*/5 \* \* \* \* svn update \/root\/tamainut\/schedule\/generico.sh && sh \/root\/tamainut\/schedule\/generico.sh/d' text.txt
sed: -e expresión #1, carácter 115: unterminated address regex
我哪里出错了?*
在sed
=>中的意思是“重复任何时间”=>使用\
:
sed '/\*\/5 \* \* \* \* svn update \/root\/tamainut\/schedule\/generico.sh && sh \/root\/tamainut\/schedule\/generico.sh/d' text.txt
您还可以将所有*
和/
替换为
(这不太可靠,但更便于编写:这是我经常做的):
*
表示在sed
=>中“重复任何时间”使用\
:
sed '/\*\/5 \* \* \* \* svn update \/root\/tamainut\/schedule\/generico.sh && sh \/root\/tamainut\/schedule\/generico.sh/d' text.txt
您还可以将所有*
和/
替换为
(这不太可靠,但更便于编写:这是我经常做的):
您可以使用:
sed '/\*\/5 \* \* \* \* svn update \/root\/tamainut\/schedule\/generico.sh && sh \/root\/tamainut\/schedule\/generico.sh/d' text.txt
但我会选择一个关键字,或几个关键字,让这行变得独一无二,并使用它们:
sed '/generico.sh.*generico.sh/d' text.txt
您的原始版本遇到问题,无法打开/
来启动正则表达式,并且*
字符是元字符,因此它们也必须转义。您可以使用:
sed '/\*\/5 \* \* \* \* svn update \/root\/tamainut\/schedule\/generico.sh && sh \/root\/tamainut\/schedule\/generico.sh/d' text.txt
但我会选择一个关键字,或几个关键字,让这行变得独一无二,并使用它们:
sed '/generico.sh.*generico.sh/d' text.txt
您的原始版本遇到问题,无法打开
/
来启动正则表达式,并且*
字符是元字符,因此它们也必须转义。如果您可以限制搜索字符串,它将清理sed代码。如果必须匹配整行,请在地址范围上使用不同的分隔符:
$ sed '\|^\*/5 \* \* \* \* svn update /root/tamainut/schedule/generico.sh && sh /root/xxxx/file.sh$|d'
$sed'\\\^\*/5\*\*\**svn update/root/tamainut/schedule/generico.sh&&sh/root/xxxx/file.sh$|d'
这样可以避免转义“/”字符。如果可以限制搜索字符串,它将清除sed代码。如果必须匹配整行,请在地址范围上使用不同的分隔符: $ sed '\|^\*/5 \* \* \* \* svn update /root/tamainut/schedule/generico.sh && sh /root/xxxx/file.sh$|d' $sed'\\\^\*/5\*\*\**svn update/root/tamainut/schedule/generico.sh&&sh/root/xxxx/file.sh$|d' 这样可以避免转义“/”字符