开发者

How to change the connection string with sed

开发者 https://www.devze.com 2023-01-04 13:15 出处:网络
I have a connection stri开发者_如何学编程ng in a ini file as following: 1 ... 2 ... 3 #someline:

I have a connection stri开发者_如何学编程ng in a ini file as following:

1 ...
2 ...
3 #someline:
n ConnectionString = "Data Source=localhost;Database=grid;User ID=grid;Password=grid;"

And I would like to locate to the line n and replcate Data Source, Database, User Id and Password field. So how can I make it in sed?


sed -e 's/localhost/DataSource/' -e 's/grid/Database/' -e 's/grid/UserId/' -e 's/grid/Password'

This assumes that the fields are always in this order, and that the string 'grid' does not appear in either the text or any previously substitued fields.


you can use awk

$ awk -vds="Datasource" -vdb="dbname" -vuser="userid" -vpswd="pass" '/Connection/{$0="Data Source="ds";Database="db";User ID="userid";Password="pswd}1' file
0

精彩评论

暂无评论...
验证码 换一张
取 消