It looks like if matching and deleting the last line confuses 'sed' so it does not recognize '$' address. Consider:
sed -e '/^3/d' -e '$ a text'
supposed to delete a line starting with '3' and then append 'text' after the last line of input. But, if it is the last line of input which starts with '3' it gets deleted but nothing is appended.
echo "1\n2\n3" | sed -e '/^3/d' -e '$ a text'
1
2
versus
echo "1\n2\n3\n4" | sed -e '/^3/d' -e '$ a text'
1
2
4
text
Is this the expected behavior or a bug?
regards, Michal.