我有一个ini
与此类似的文件
[test]
foo=bar
如果我们称之为ini
文件为test1.ini
我如何改变的值foo
to foobarbaz
例如使用shell script
.
我已经尝试过以下方法,但它对我不起作用。我在 ini 文件中没有看到更新的更改。我该怎么写呢?
sed "/^foo=/s/=.*/=foobarbaz/" < test1.ini
你有什么其他的建议
我个人使用更详细的sed
命令,因为相同的选项可能出现在几个不同的部分中:
sh$ sed -i.bak '/^\[test]/,/^\[/{s/^foo[[:space:]]*=.*/foo = foobarbaz/}' test1.ini
# ^^^^^^ ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# make a in the right perform the substitution
# *backup* section as you want
作为安全网,我想补充一点:
sh$ diff test1.ini{,.bak}
2c2
< foo = foobarbaz
---
> foo=bar
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)