Menu
Newbedev LogoNEWBEDEV Python Javascript Linux Cheat sheet
Newbedev LogoNEWBEDEV
  • Python 1
  • Javascript
  • Linux
  • Cheat sheet
  • Contact

How to replace a string with a string containing slash with sed?

Use another character as delimiter in the s command:

printf '%s\n' "$srcText" | sed "s|XPLACEHOLDERX|$connect|"

Or escape the slashes with ksh93's ${var//pattern/replacement} parameter expansion operator (now also supported by zsh, bash, mksh, yash and recent versions of busybox sh).

printf '%s\n' "$srcText" | sed "s/XPLACEHOLDERX/${connect//\//\\/}/"

If your shell supports it:

"${srcText/XPLACEHOLDERX/$connect}"

Tags:

Sed

Related

monitor files (à la tail -f) in an entire directory (even new ones) How to get permission number by string : -rw-r--r-- Recursively list files with file names, folder names and permission How can I profile a shell script? Trap, ERR, and echoing the error line ssh command unexpectedly continues on other system after ssh terminates Remove numbers from filenames Allow non-admin users to install packages via apt or rpm? How to make Chinese characters display properly on Chromium Difference between ifconfig and ipconfig? Command substitution: splitting on newline but not space VSFTPD, 553 Could not create file. - permissions?

Recent Posts

Pandas how to find column contains a certain value Recommended way to install multiple Python versions on Ubuntu 20.04 Build super fast web scraper with Python x100 than BeautifulSoup How to convert a SQL query result to a Pandas DataFrame in Python How to write a Pandas DataFrame to a .csv file in Python
© 2021 newbedevPrivacy Policy