更新时间:2023-09-01 19:12:58
您可以使用两个地址的形式:
You could make use of two-address form:
sed '0,/tat/{/tat/d;}' inputfile
这将删除模式的首次出现.
This would delete the first occurrence of the pattern.
从info sed
报价:
A line number of `0' can be used in an address specification like
`0,/REGEXP/' so that `sed' will try to match REGEXP in the first
input line too. In other words, `0,/REGEXP/' is similar to
`1,/REGEXP/', except that if ADDR2 matches the very first line of
input the `0,/REGEXP/' form will consider it to end the range,
whereas the `1,/REGEXP/' form will match the beginning of its
range and hence make the range span up to the _second_ occurrence
of the regular expression.