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

No comments:

Post a Comment

qz-l.com — A Simple, Clean, and Fast URL Shortener I Built

 Lately, I’ve noticed that many URL shortener services are becoming cluttered — full of ads, tracking, and unnecessary steps. I wanted somet...