7

I am trying to understand a shell script that uses sed. I found that there were some places where sed was invoked with the -e option.

I tried to see the man page and it just mentions,

-e command

Append the editing commands specified by the command argument to the list of commands.

which is not very clear to me.

Can someone kindly explain to me what the -e does? Thanks.

PS: I am using sed in mac

9

The -e parameters tells sed that you wish to supply multiple commands:

sed -e 's/string1/string2/g' -e 's/string4/string5/g'

This will replace string1 with string2 and string4 with string5.

| improve this answer | |
  • Thanks. That explains it. Now the cryptic message in the man command makes sense. – Sudar Apr 15 '13 at 11:06
  • :-) glad to be of help – Sean Landsman Apr 15 '13 at 11:07
  • 1
    Why is this the accepted answer? It still does not truly reveal the true purpose of -e because the above script can be done similarly by: sed 's/string1/string2/g;s/string4/string5/g' file. Whatever separate expressions you have, you can fuse them into 1 expression and then drop the -e. Can somebody please reveal the necessity purpose of -e in sed? – eigenfield Oct 22 '18 at 17:19
  • 1
    @daixtr It's explained in this answer. – weibeld Jan 31 '19 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.