Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between `sed -i -e` and `sed -ie`?

Tags:

bash

unix

sed

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.

like image 449
mrgloom Avatar asked Apr 24 '17 07:04

mrgloom


People also ask

How many types of sed are there?

Four Types of sed Scripts.

What is sed used for?

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.

What is the difference between sed and awk?

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.

What does sed 1 mean?

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.


2 Answers

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)

like image 180
sat Avatar answered Sep 27 '22 20:09

sat


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.

like image 41
jehutyy Avatar answered Sep 27 '22 22:09

jehutyy