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: sed
19-Apr-2011
6:11 am
Thanks for this. Came across the exact thing today, and this helped greatly.
06-May-2011
8:35 pm
I knew I am not the only one puzzled by that. :)
15-Sep-2015
4:25 am
Thanks, I couldn’t figure this out!
06-Jan-2016
8:17 pm
Thanks, this is a great help.
19-Jun-2018
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!