使用shell脚本修改ini文件 [英] Modifying ini files using shell script
本文介绍了使用shell脚本修改ini文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个与此相似的ini
文件
I have an ini
file similar to this
[test]
foo=bar
,如果我们将此ini
文件称为test1.ini
and if we call this ini
file as test1.ini
如何例如使用shell script
将foo
的值更改为foobarbaz
.
How do I change the value of foo
to foobarbaz
for example using shell script
.
我尝试了以下操作,但它对我不起作用.我没有在ini文件中看到更新的更改.我该怎么写?
I have tried the following and it doesn't work for me. I don't see the updated changes in the ini file. how do I write it?
sed "/^foo=/s/=.*/=foobarbaz/" < test1.ini
您还有其他建议吗
推荐答案
要更新文件,请使用sed的-i
选项:
To have the file updated, use the -i
option of sed:
sed -i "/^foo=/s/=.*/=foobarbaz/" test1.ini
来自man sed
:
- i [SUFFIX] ,-就地[= SUFFIX]
就地编辑文件(如果提供SUFFIX,则进行备份)
edit files in place (makes backup if SUFFIX supplied)
所以你也可以做
sed -i.bak "/^foo=/s/=.*/=foobarbaz/" test1.ini
这篇关于使用shell脚本修改ini文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文