更新时间:2023-02-12 19:18:59
在sed
正则表达式中,您必须转义(
,|
和)
.
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/\b\($dellist\)\b//g" benoietigte_packete.list
我添加了\b
,因此它只匹配整个单词.
I've added the \b
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.