如何通过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
就会失败。