2

sed uses basic regular expressions (BRE) by default. Some implementations offer an option to switch to extended regular expressions instead.

GNU sed introduced the -r option to do so in version 3.01 from 1998 (see research). Later, in version 4.2 from 2009, -E was added as an undocumented synonym for -r to be compatible with BSD implementations. The synonym was first documented in 2013 (see commit) and then released in version 4.3 from 2017.

Since then GNU sed claims -E to be POSIX.

From man sed and sed --help

-E, -r, --regexp-extended
use extended regular expressions in the script (for portability use POSIX -E).

From the online manual

the -E extension has since been added to the POSIX standard (http://austingroupbugs.net/view.php?id=528), so use -E for portability

And from the commit message that introduced these claims

"-E" is now in POSIX. See: http://austingroupbugs.net/view.php?id=528

However, I cannot find sed -E in any POSIX standard. In the latest version I could find, the only documented options were -e, -f, and -n.

The Open Group Base Specifications Issue 7, 2018 edition
IEEE Std 1003.1-2017 (Revision of IEEE Std 1003.1-2008)
Copyright © 2001-2018 IEEE and The Open Group

NAME
sed - stream editor

SYNOPSIS
sed [-n] script [file...]
sed [-n] -e script [-e script]... [-f script_file]... [file...]
sed [-n] [-e script]... -f script_file [-f script_file]... [file...]

Question:

  • Is sed -E actually specified by POSIX?
  • If yes, in which version and where can I read it?
  • If not, how come these claims survived for 8 years and 9 versions of GNU sed?
Socowi
  • 625

0 Answers0