1

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?

NightShadeQueen
  • 2,946
  • 3
  • 19
  • 35
user2722449
  • 29
  • 1
  • 3
  • possible duplicate of [sed substitution with bash variables](http://stackoverflow.com/questions/7680504/sed-substitution-with-bash-variables) – tripleee Sep 21 '15 at 03:17

1 Answers1

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 
John1024
  • 97,609
  • 11
  • 105
  • 133
  • thanks for ur reply.....the first line in the file is [3_go:wf_test:s_test]...so will this comand skip this line go to second line?....thank you – user2722449 Sep 19 '15 at 05:45
  • @user2722449 The current version will leave that line unchanged. Did you want it removed? – John1024 Sep 19 '15 at 05:58