sed 就地编辑文件 [英] sed edit file in place
本文介绍了sed 就地编辑文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否可以在单个 sed 命令中编辑文件,而无需手动将编辑的内容流式传输到新文件中,然后重命名新文件改为原文件名.我尝试了 -i
选项,但我的 Solaris 系统说 -i
是一个非法选项.有什么不同的方法吗?
I am trying to find out if it is possible to edit a file in a single sed command without manually streaming the edited content into a new file and then renaming the new file to the original file name. I tried the -i
option but my Solaris system said that -i
is an illegal option. Is there a different way?
推荐答案
-i
option 将编辑过的内容流式传输到一个新文件中,然后在幕后重新命名.
The -i
option streams the edited content into a new file and then renames it behind the scenes, anyway.
示例:
sed -i 's/STRING_TO_REPLACE/STRING_TO_REPLACE_IT/g' filename
和
sed -i '' 's/STRING_TO_REPLACE/STRING_TO_REPLACE_IT/g' filename
在 macOS 上.
这篇关于sed 就地编辑文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文