sed match exactly and delete

I am using following sed rule to delete 2 lines after a pattern match inclusive.

[root@server ~]# cat /tmp/temp.txt
dns.com
11
22
mydns.com
11
22
dns.com.au
11
22
LAST LINE
[root@server ~]# cat  /tmp/temp.txt | sed -e '/dns.com/,+2d'

LAST LINE

I just need to remove lines below dns.com only and NOT below other domains. The rule I am using deletes lines below mydns.com and dns.com.au

sed '/^dns\.com$/ {p;N;N;d;}' /tmp/temp.txt
1 Like

Try:

sed '/^dns\.com$/,+2d' /tmp/temp.txt
1 Like

Anchor the pattern :

sed -e '/^dns.com$/,+2d' file
mydns.com
11
22
dns.com.au
11
22
LAST LINE
1 Like

Following up on MadeInGermany's more standard sed solution,
I suppose the OP needs something like this:

sed '/^dns\.com$/ {N;N;d;}' /tmp/temp.txt
1 Like

Thank you all. It works pefectly.