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

偶尔善良 提交于 2021-02-04 17:33:26

问题


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.


回答1:


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)




回答2:


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.



来源:https://stackoverflow.com/questions/43582494/what-is-the-difference-between-sed-i-e-and-sed-ie

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!