What is the difference between sed -i -e
and sed -ie
?
It's not very clear from help
sed --help
-e script, --expression=script
add the script to the commands to be executed
In second case it creates some backup file?
In general Unix utils do not permit to combine flags?
Just an example to show what is happening:
echo "bla" > 1.txt
cat 1.txt
bla
sed -i -e 's:bla:blakva:g' 1.txt
cat 1.txt
blakva
sed -ie 's:bla:blakva:g' 1.txt
cat 1.txt
blakvakva
*Note: also 1.txte is created, containing
cat 1.txte
blakva
Also not still sure what is -e
doing in my example, because sed -i 's:bla:blakva:g' 1.txt
works too.
Four Types of sed Scripts.
The sed command, short for stream editor, performs editing operations on text coming from standard input or a file. sed edits line-by-line and in a non-interactive way. This means that you make all of the editing decisions as you are calling the command, and sed executes the directions automatically.
The main difference between sed and awk is that sed is a command utility that works with streams of characters for searching, filtering and text processing while awk more powerful and robust than sed with sophisticated programming constructs such as if/else, while, do/while etc.
sed(1) is a non-interactive text editor that comes with UNIX since Version 7 AT&T UNIX. It's main purpose is to be used in scripts.
When you give sed -i -e
, sed
sees two options.
But, When you give sed -ie
, sed
sees -i
option only with suffix
as e
. That is the reason you got file backup with e
suffix.
From
man sed
:-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if SUFFIX supplied)
Option -i
means that it modify in-place the file you are sed-ing. Otherwise sed
just show what modification were done. If you add a suffix after -i
(e.g -i.bck
) it will backup your input file then add the suffix provided.
Option -e
allow you to provide sed script instead of command line arguments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With