更新时间:2023-02-12 20:47:54
在 sed
正则表达式中,你必须转义 (
, |
, and)代码>.
In sed
regexps you have to escape (
, |
, and )
.
您还需要使用 g
修饰符,以便它替换该行上的所有匹配项,而不仅仅是第一个匹配项.
You also need to use the g
modifier so it replaces all matches on the line, not just the first match.
dellist="package24|package66"
# escape the pipes
dellist=${dellist//|/\|}
sed "s/($dellist)//g" benoietigte_packete.list
我添加了 所以它只匹配整个单词.
I've added the so it only matches whole words.
根据您拥有的 sed
版本,您还可以使用 -E
或 -r
选项来使用扩展的正则表达式.
Depending on the version of sed
you have, you can also use the -E
or -r
options to use extended regular expressions.