user4763550
user4763550

Reputation: 121

Difference between sed -e and sed -f

What is the difference between sed -e and sed -f options. Which of these should be used for in place editing. I was not able to understand their meaning clearly from the man pages.

Upvotes: 2

Views: 971

Answers (2)

Anurag Saran
Anurag Saran

Reputation: 301

According to the manual page of sed

-e script --expression=script Add the commands in script to the set of commands to be run while processing the input

This means that sed would be executing the commands passed directly to it on the command-line itself such as sed -e 's/foo/bar/g'

Where as, -f script-file --file=script-file Add the commands contained in the file script-file to the set of commands to be run while processing the input.

while using -f sed would be expecting the commands in the file specified after -f option. This is generally useful for complex operations.

As long as in place editing is concerned, any of the options can be used. For example:

sed -i -e 's/foo/bar/g'

Upvotes: 2

DarkDust
DarkDust

Reputation: 92384

sed -e <commands> executes the commands passed on the command line, like sed -e s/foo/bar/, while sed -f <file> executes the commands found in the passed file.

None of them relate to inplace editing. That's -i <backup_extension>. If no extension is passed (like sed -i '' -e s/foo/bar/ file_to_edit), no backup is made.

Upvotes: 1

Related Questions