最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

bash - Update odbc.ini file with new parameter in the section using shell scripting - Stack Overflow

programmeradmin3浏览0评论

I have an odbc.ini file similar to this

[Test]
Driver=/path/to/driver
Database=test_db

[AnotherSection]
Driver=/another/pathhere

when I run below command, it is adding the Password=5432 at the beginning of the section. Instead I need it at the end of the section [Test]

sed '/^\[Test\]/ a Password=5432}' odbc.ini
[Test]
Password=5432
Driver=/path/to/driver
Database=test_db

[AnotherSection]
Driver=/another/path

expected:

[Test]
Driver=/path/to/driver
Database=test_db
Password=5432

[AnotherSection]
Driver=/another/path

Any suggestions please

I have an odbc.ini file similar to this

[Test]
Driver=/path/to/driver
Database=test_db

[AnotherSection]
Driver=/another/pathhere

when I run below command, it is adding the Password=5432 at the beginning of the section. Instead I need it at the end of the section [Test]

sed '/^\[Test\]/ a Password=5432}' odbc.ini
[Test]
Password=5432
Driver=/path/to/driver
Database=test_db

[AnotherSection]
Driver=/another/path

expected:

[Test]
Driver=/path/to/driver
Database=test_db
Password=5432

[AnotherSection]
Driver=/another/path

Any suggestions please

Share Improve this question asked Jan 17 at 22:07 user3795378user3795378 254 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

With GNU sed:

sed -e '/\[Test\]/,/^$/{/^$/{i Password=5432' -e '}}' file.ini

Output:

[Test]
Driver=/path/to/driver
Database=test_db
Password=5432

[AnotherSection]
Driver=/another/pathhere

I assume that the section is followed by a blank line.

发布评论

评论列表(0)

  1. 暂无评论