Dmitry Leskov

Mysterious GNU sed option “-E”

A few days ago I needed to conduct a mass search and replace operation on a large text file, and figured that sed would be a good fit. I must admit that sed is not on the list of tools I use daily, so I just looked up a solution to a similar problem on the Net. It worked, but the command line contained an option I’ve never seen before – capital “E“:

sed -E . . .

Without -E, the command failed, so I decided to find out what that option means. However, it seemed to be undocumented: neither sed --help nor man sed or info sed mentioned it.

Fast forward a few minutes, and I have the answer: it is simply equivalent to “-r“!

           .  .  .
        /* Undocumented, for compatibility with BSD sed.  */
        case 'E':
        case 'r':
          if (extended_regexp_flags)
          extended_regexp_flags = REG_EXTENDED;
           .  .  .

Sigh. Every now and then I wish Unix was never forked or cloned.

I also wondered if there is reciprocity on the BSD side, but I only have access to an old box running FreeBSD 4.11 – the version of sed included with it does not recognize the “-r” option…


« | »


  1. Andrew Myers
    6:11 am

    Thanks for this. Came across the exact thing today, and this helped greatly.

  2. bdlc-editor
    8:35 pm

    I knew I am not the only one puzzled by that. :)

  3. Andrés Mejía
    4:25 am

    Thanks, I couldn’t figure this out!

  4. Apache Indian
    8:17 pm

    Thanks, this is a great help.

  5. Thrawn
    4:59 pm

    Thank you very much! Came across the issue just now with a configure script calling ‘sed -E’ explicitly, which failed on my GNU sed version 4.1.5 (old CygWin install). Changed to -r, and it seems to work now!

* Copy This Password *

* Type Or Paste Password Here *