Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 610
Mint Avatar asked Jun 29 '10 08:06

Mint


People also ask

What does sed do?

The sed command stands for stream editor in UNIX-based systems. It performs text editing operations on text coming from the standard input or a file. It can perform operations such as deletion, searching, find and replace, or insertion in a file even without opening it.

What does sed 1d do?

' means: delete the first line in file "file_name" at place and backup to file. (just like edit file and delete first line directly. )

What is sed in shell script?

The SED command in Linux stands for Stream EDitor and is helpful for a myriad of frequently needed operations in text files and streams. Sed helps in operations like selecting the text, substituting text, modifying an original file, adding lines to text, or deleting lines from the text.


1 Answers

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.

like image 117
czchen Avatar answered Sep 20 '22 20:09

czchen