问题
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