Corneliu Pacurar Corneliu Pacurar - 7 months ago 8
Bash Question

How do i delete first 2 lines which match with a text given by me ( using sed )?

How do i delete first 2 lines which match with a text given by me ( using sed ! )

E.g :

#file.txt contains following lines :
abc
def
def
abc
abc
def


And i want to delete first 2 "abc"

Answer

sed is for simple substitutions on individual lines, that is all. For anything else you should be using awk:

$ awk '!(/abc/ && ++c<3)' file
def
def
abc
def