-1

I have an environment variable LIB_HOME=/etc/temp In one of the config files, i'm trying to replace entire line using sed command as follows

sed -i '/lib.home=/c\lib.home=$LIB_HOME' myconfig.properties

Actual Output : lib.home=blablabla ===> lib.home=$LIB_HOME

Expected Output : lib.home=blablabla ===> lib.home=/etc/temp

Please help

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Praveen
  • 29
  • 2
  • replace the single quotes `'` with double quotes `"` - you are not allowing the shell to substitute. – kabanus Sep 06 '18 at 13:12
  • Kabanus, i tried the command as follows == sed -i '/lib.home=/c\lib.home=$LIB_HOME' myconfig.properties == still the output is "lib.home=$LIB_HOME". Please help me with command – Praveen Sep 06 '18 at 13:17

1 Answers1

0

Have you tried using double quotes?

sed -i '/lib.home=/c\lib.home=‘“$LIB_HOME”' myconfig.properties
vk-code
  • 950
  • 12
  • 22
  • Yes Vikram. Output is lib.home="$LIB_HOME". But expected output is lib.home=/ect/temp – Praveen Sep 06 '18 at 13:24
  • With GNU sed: `LIB_HOME="/etc/temp"; sed -Ei 's|(lib.home=).*|\1'"$LIB_HOME"'|' myconfig.properties` – Cyrus Sep 06 '18 at 13:36
  • for me it worked, may be the quote using mobile device are wrong `# cat > myconfig.properties lib.home= # LIB_HOME="/etc/temp"; sed -i '/lib.home=/c\lib.home='"$LIB_HOME" myconfig.properties # cat myconfig.properties lib.home=/etc/temp` `# sed --version sed (GNU sed) 4.2.2` – vk-code Sep 06 '18 at 14:07
  • Thanks Cyrus.. Your suggestion worked for me.. – Praveen Sep 10 '18 at 13:14
  • Thanks Vikram for your valuable suggestion.. – Praveen Sep 10 '18 at 13:15