在一个 sed 中匹配负模式和正模式

Matching negative and positive pattern in one sed

我在制作 sed 命令时遇到问题,该命令会更改行,其中出现 =sometext= 并将其更改为另一个模式,但当该行中出现 https 时不会执行此操作。我不知道该如何更改此命令:sed -i 's/=\([^=]*\)=/{{}}/g'

您需要阅读有关匹配行的 sed 手册:https://www.gnu.org/software/sed/manual/sed.html 第 4 章:

The following command replaces the word ‘hello’ with ‘world’ only in lines not containing the word ‘apple’:

sed '/apple/!s/hello/world/' input.txt > output.txt

使用多个块,例如:

sed '/=sometext=/ { /https/b; s/.../.../; }'