sed replace shell variable which include slash ('/')

Test content

cat test-sed.txt
aaa/bbb/ccc/ddd/eee
fff/ggg/ss

replace "ccc/ddd" to "CCC/DDD" via sed

NEW_STRING="CCC/DDD"
sed -i "s:ccc/ddd:${NEW_STRING}:" test-sed.txt

Notes:

  1. use ':' as seperate char rather than '/', which is default
  2. use "" include the replace command

LengErrong

ss://Y2hhY2hhMjAtaWV0Zi1wb2x5MTMwNTpqZXN1c2lzbG92ZUAzNS4yMDIuMjM4LjI0Ojg5MTE#Outline

Read More