Other than GNU, OpenBSD's sed does not like the "( |$)" statement. I do not know, which behaviour is "right" according to POSIX. The attached patch should make things work on all systems though.