bash `sed -i -e` 和 `sed -ie` 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43582494/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between `sed -i -e` and `sed -ie`?
提问by mrgloom
What is the difference between sed -i -e
and sed -ie
?
It's not very clear from help
sed --help
sed -i -e
和 和有什么不一样sed -ie
?帮助不是很清楚
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?
一般来说,Unix utils 不允许组合标志?
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.
也不确定-e
在我的例子中做了什么,因为sed -i 's:bla:blakva:g' 1.txt
也有效。
采纳答案by sat
When you give sed -i -e
, sed
sees two options.
当你给sed -i -e
,sed
看到两个选项。
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.
但是,当您给 时sed -ie
,只能sed
看到-i
选项suffix
as e
。这就是您获得带e
后缀的文件备份的原因。
From
man sed
:-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if SUFFIX supplied)
来自
man sed
:-i[后缀], --in-place[=后缀]
就地编辑文件(如果提供 SUFFIX,则进行备份)
回答by jehutyy
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.
选项-i
意味着它就地修改您正在 sed-ing 的文件。否则sed
只显示进行了哪些修改。如果您在-i
(例如-i.bck
)之后添加后缀,它将备份您的输入文件,然后添加提供的后缀。
Option -e
allow you to provide sed script instead of command line arguments.
选项-e
允许您提供 sed 脚本而不是命令行参数。