A shell script to to change a value in a file with a parameter

人走茶凉 提交于 2019-12-25 06:07:19

问题


I am an etl developer, am very new to shell scripting,

My file is param.prm

[3_go:wf_test:s_test]

$Dbconnection=abcd

$Dbstring=qwert

I need a shell script to to read the above file and change the value of $dbconnection (now abcd) dynamically with the variable I pass , every time I run the script. How can I do that?


回答1:


$ sed 's/\($Dbconnection=\).*/\1NewValue/' param.prm 
[3_go:wf_test:s_test]

$Dbconnection=NewValue

$Dbstring=qwert

To change the file in-place, use the -i option. For GNU sed:

sed -i 's/\($Dbconnection=\).*/\1NewValue/' param.prm 

For BSD (OSX) sed:

sed -i "" 's/\($Dbconnection=\).*/\1NewValue/' param.prm 


来源:https://stackoverflow.com/questions/32664080/a-shell-script-to-to-change-a-value-in-a-file-with-a-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!