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)
            usage(4);
          extended_regexp_flags = REG_EXTENDED;
          break;
           .  .  .

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…

Tags:

« | »

Talkback

  1. Andrew Myers
    19-Apr-2011
    6:11 am
    1

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

  2. bdlc-editor
    06-May-2011
    8:35 pm
    2

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

  3. Andrés Mejía
    15-Sep-2015
    4:25 am
    3

    Thanks, I couldn’t figure this out!

  4. Apache Indian
    06-Jan-2016
    8:17 pm
    4

    Thanks, this is a great help.

* Copy This Password *

* Type Or Paste Password Here *