我相当确定我错过了一些明显的东西!
$ cat test.txt
00 30 * * * /opt/timebomb.sh >> timebomb.log
01 30 * * * /opt/reincarnate.sh >> reincarnation.log
$ sed ':timebomb:d' test.txt
00 30 * * * /opt/timebomb.sh >> timebomb.log
01 30 * * * /opt/reincarnate.sh >> reincarnation.log
鉴于
$ sed '/timebomb/d' test.txt
01 30 * * * /opt/reincarnate.sh >> reincarnation.log
为什么会这样呢?d
命令不支持一组不同的分隔符吗?
发布于 2009-11-26 00:04:09
在sed中,冒号在标签之前,因此您的sed程序看起来像是两个没有发生任何事情的标签。如果在s命令之前,解析器可以将冒号视为分隔符,所以这是一个特例。
发布于 2009-11-26 08:08:31
使用gawk
gawk '!/timebomb/' file > newfile
发布于 2009-11-26 09:11:09
您可以只使用shell,不需要外部工具
while read -r line
do
case "$line" in
*timebomb* ) continue;;
*) echo "$line";;
esac
done <"file"
https://stackoverflow.com/questions/1797906
复制相似问题