例如:
aaa bbb
aaa ccc
aaa
bbb
hij
匹配后的结果是
aaa bbb
hij
尝试过的
sed -e '/\(aaa\)[^\(bbb\)]*$/d' test.txt
在手册http://www.gnu.org/software/sed/manual/sed.html上给出的
regexp1\|regexp2
Matches either regexp1 or regexp2. Use parentheses to use complex alternative regular expressions. The matching process tries each alternative in turn, from left to right, and the first one that succeeds is used. It is a GNU extension.
regexp1regexp2
Matches the concatenation of regexp1 and regexp2. Concatenation binds more tightly than \|, ^, and $, but less tightly than the other regular expression operators.
也看了这里的一些参考:
http://coolshell.cn/articles/9104.html
请参考 Sed regex and substring negation
mac 上执行:
输出为: