【发布时间】:2022-01-19 09:21:54
【问题描述】:
我正在处理这个看起来像这样的数据文件:
text in file
hello random text in file
example text in file
words in file hello
more words in file
hello text in file can be
more text in file
我正在尝试使用 sed 将所有 不 包含字符串 hello 的行替换为 match,因此输出将是:
match
hello random text in file
match
words in file hello
match
hello text in file can be
match
我尝试使用sed '/hello/!d',但这会删除该行。另外,我读到我可以在 sed 中使用 ! 进行匹配,但我不确定如何匹配每一行并正确替换。如果您能给我一些指导,我将不胜感激。
【问题讨论】: