Skip to content
Advertisement

Whats the difference between sed -E and sed -e

I’m working on some old code and I found that I used to use

sed -E 's/findText/replaceWith/g' #findText would contain a regex

but I now try

sed -e 's/findText/replaceWith/g'

It seems to do the same thing, or does it? I kinda remember there being a reason I done it but I can’t remember and doing “man sed” doesn’t help as they don’t have anything about -E only -e that doesn’t make much sense ether.

-e, --expression=script
  Append the editing commands in script to the end of 
  the editing command script. script may contain more 
  than one newline separated command.

I thought -e meant it would match with a regex…

GNU sed version 4.2.1

Advertisement

Answer

From source code, -E is an undocumented option for compatibility with BSD sed.

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

And from manual, -E in BSD sed is used to support extended regular expressions.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement