Stop sed from mangling your config files when your delimiters are everywhere
Text Processing (Grep/Sed/Awk)
Stop sed from mangling your config files when your delimiters are everywhere
🧩 The Challenge
Dealing with file paths or URLs in a sed substitution is a nightmare because every slash breaks the command. I spent way too much time backslash-escaping paths before realizing there was a cleaner way.
💡 The Fix
You can use almost any character as a delimiter in sed so you don’t have to keep tripping over the forward slash. Just pick a character that isn’t in your string, like a pipe or a hash.
sed -i 's|/var/www/html/site1|/opt/www/site2|g' /etc/nginx/sites-available/default
⚙️ Why It Works
By changing the delimiter, you stop the regex engine from trying to parse your path separators as end-of-command markers. It makes the expression readable and saves you from the inevitable syntax error.
🚀 Pro-Tip: Use a pipe symbol | as your default sed delimiter for paths and you’ll save yourself a world of headache.
Linux Tips & Tricks | © ngelinux.com | 8/16/2026
