本文介绍了sed命令使用-i选项未能在Mac上,但在Linux上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经成功地使用了以下 SED
命令搜索/ Linux中替换文本:
SED -i'S / old_link / new_link / G'*
然而,当我尝试在我的Mac OS X,我得到:
I thought my Mac runs a normal BASH shell. What's up?
EDIT:
According to @High Performance, this is due to Mac sed
being of a different (BSD) flavor, so my question would therefore be how do I replicate this command in BSD sed
?
EDIT:
Here is an actual example that causes this:
sed -i 's/hello/gbye/g' *
解决方案
If you use the -i option you need to provide an extension for your backups.
If you have:
File1.txt
File2.cfg
The command:
sed -i '.original' 's/old_link/new_link/g' *
create 2 backup files like:
File1.txt.original
File2.cfg.original
You can use
sed -i '' 's/old_link/new_link/g' *
to ignore backups.
这篇关于sed命令使用-i选项未能在Mac上,但在Linux上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!