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
精彩评论