如何通过sed删除匹配的第一行

如何通过sed删除匹配的第一行,sed,Sed,我有这样的文件,现在我只想删除第一个def_xxx abc_xxx def_xxx ghi_xxx abc_yyy def_yyy ghi_yyy 它删除了两行def_xxx,def_yyy sed -e '/def/d' myfile.txt 如何删除唯一的第一行def_xxx sed -e '0,/def/{/def/d;}' myfile.txt 这将删除图案的第一个引用 在其手册中: 0,addr2 Start out in "matched first address&

我有这样的文件,现在我只想删除第一个
def_xxx

abc_xxx
def_xxx
ghi_xxx
abc_yyy
def_yyy
ghi_yyy
它删除了两行
def_xxx
def_yyy

sed -e '/def/d' myfile.txt
如何删除唯一的第一行
def_xxx

sed -e '0,/def/{/def/d;}' myfile.txt
这将删除图案的第一个引用

在其手册中:

0,addr2
Start out in "matched first address" state, until addr2 is found. This is similar
to 1,addr2, except that if addr2 matches the very first line of input the 
0,addr2 form will be at the end of its range, whereas the 1,addr2 form will 
still be at the beginning of its range. This works only when addr2 is a 
regular expression.

Ref:

如果实际有一个更大的文件带有其他前缀行,那么最好提供完整的
def_xxx
,但答案很好。使用完整模式。如果在
def_xxx
之前有一个
def_www
,只需使用
def
就会失败。