8

On BSD sed, -E is the "extended regex" flag. On GNU sed, the documentation states that -r is the extended regex flag, but the -E switch works as well (though undocumented in my research).

I recall reading somewhere that -E will be specified in the next edition of POSIX specifications, but I can't find where I read that.

(Is that true? Is there an authoritative reference for that, or a user here who is an authority?)

Just how portable is the -E switch for sed?

Are there standard (i.e. POSIX compliant) versions of sed on which -E is unsupported? (Which ones?)

Why is the -E flag not documented for GNU sed?

Wildcard
  • 35,316
  • 26
  • 130
  • 258
  • 1
    I can't explain why they did it, but the source for GNU sed includes the comment about processing `-E`: `/* Undocumented, for compatibility with BSD sed. */` and handles it exactly the same as `-r` – Eric Renouf Sep 17 '16 at 00:50
  • @EricRenouf, Nice find; can you provide a link also? :) – Wildcard Sep 17 '16 at 01:01
  • 1
    As it happens, I was luck with the version of source I was looking at, but I'll do you one better now. [Here's the commit](http://git.savannah.gnu.org/cgit/sed.git/commit/sed/sed.c?id=8b65e07904384b529a464c89f3739d2e7e4d5135) where the comment I cited was removed, and it includes there the log message "Modify documentation to note sed "-E" option, now in POSIX, for EREs.", which was made in 2013-10-16, so I'm surprised it hasn't made it into the docs or similar, though my Cent OS 7 box has a version from 2012 still – Eric Renouf Sep 17 '16 at 01:07
  • 1
    That said, I can't find the reference to it in the latest (I think) POSIX doc for sed – Eric Renouf Sep 17 '16 at 01:12
  • @EricRenouf, That commit (and the [page linked from it](http://austingroupbugs.net/view.php?id=528)) answers nearly every part of my question. Could you please make your comment an answer? :) – Wildcard Sep 17 '16 at 01:12

2 Answers2

8

GNU first added undocumented support for -E just to be compatible with BSD syntax, and the source included the comment

/* Undocumented, for compatibility with BSD sed. */

But in 2013 that was removed in this commit with the log message

Modify documentation to note sed "-E" option, now in POSIX, for EREs.

and the commit references a defect tracker for POSIX at this page that marks as accepted adding the -E flag to the sed arguments

It doesn't seem to have made it into the latest POSIX spec (sed specific part) though, but I guess it's coming.

Eric Renouf
  • 18,141
  • 4
  • 49
  • 65
  • Of course it is also missing from older distros. I've just discovered that the Sed included in RHEL 5 doesn't support `-E`, though it *does* support `-r`. (This might seem obvious for environments that include old systems, but *I* had forgotten to check.) – Wildcard Oct 20 '16 at 21:51
  • @Wildcard I guess that makes sense. Since they added the `-E` to be compatible with other flags, there had to be a time that predated that addition – Eric Renouf Oct 21 '16 at 16:34
  • `-E` still hasn't arrived in POSIX. The [Austin Group Issue](https://www.austingroupbugs.net/view.php?id=528) has it tagged for POSIX Issue 8. [POSIX drafts are available (with effort)](https://unix.stackexchange.com/a/607346/143394) – Tom Hale Sep 01 '20 at 11:01
6

The place to look is at systems which are certified:

OSX has it, though whether it's BSD- or GNU-first was not part of the question.

Thomas Dickey
  • 75,040
  • 9
  • 171
  • 268