| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
Encountered this one yesterday and thought I'd bring it to light.
On a GNU system this works:
sed -n '/pattern/{s/foo/bar/p}'
but fails on BSD sed (tested on OpenBSD & FreeBSD)
sed: 1: "/pattern/{s/foo/bar/p}": bad flag in substitute command: '}'
This is actually POSIX which requires a newline or semicolon before a
close-brace:
"The <right-brace> shall be preceded by a <newline> or <semicolon>
(before any optional <blank> characters preceding the <right-brace>)."
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html#tag_20_116_13_03
Thus on a BSD system it needs to have the extra semi-colon:
sed -n '/pattern/{s/foo/bar/p;}'
Unfortunately, I suspect that a lot of scripts out there depend on
the GNU-specific relaxed (but POSIX-violating) rules, so enforcing
the POSIX will likely break them. However, I also know that a number
of GNU tools respect a POSIXLY_CORRECT environment variable which
might be useful in this situation.
And now you know too.
-tim