Shell – the purpose of -e in sed command

commandlinuxsedshelltext;

I can't find any documentation about the sed -e switch, for simple replace, do I need it?

e.g.

sed 's/foo/bar/'

VS

sed -e 's/foo/bar/'

Best Answer

From the man page:

-e script, --expression=script

    add the script to the commands to be executed

So you can use multiple -e options to build up a script out of many parts.

$ sed -e "s/foo/bar/" -e "/FOO/d"

Would first replace foo with bar and then delete every line containing FOO.

Related Question