Daniel
Daniel

Reputation: 2005

What is the usage of -e flag in sed?

From some online reading, it seems that sed's -e flag usage is to note a sed script

e.g:

sed -i -e 's/default_language/language/g' "$CONF_FILE"

but from self-testing and some online search, it seems that this line should also work:

sed -i 's/default_language/language/g' "$CONF_FILE"

So what do I need -e for? Is it only useful for cases I'd like to write several scripts in a row? That can also be managed with ;.

Upvotes: 2

Views: 1948

Answers (1)

pynexj
pynexj

Reputation: 20728

According to the manual:

If no -e, --expression, -f, or --file option is given, then the first non-option argument is taken as the sed script to interpret. All remaining arguments are names of input files; if no input files are specified, then the standard input is read.

As you already mentioned, -e may be used for multiple commands.

sed 'cmd1; cmd2'
sed -e 'cmd1; cmd2'
sed -e 'cmd1' -e 'cmd2'

Upvotes: 6

Related Questions