开发者

How to change the connection string with sed

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜