Corneliu Pacurar Corneliu Pacurar - 2 years ago 58
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 Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download