Text Processing (Grep/Sed/Awk)
Stop sed from mangling your config files when you use special characters
🧩 The Challenge
Trying to use sed to replace a path string like /var/www/html in a config file is a special kind of hell because the forward slashes keep breaking the command syntax. I’ve wasted way too much time wrestling with backslash escapes just to change a simple file path.
💡 The Fix
Switch the delimiter to something that isn’t in your path, like a pipe or a colon. It saves you from having to type an endless stream of escape characters that nobody remembers to read correctly anyway.
sed -i 's|/var/www/html|/srv/newpath|g' config.conf
⚙️ Why It Works
Using a different character immediately after the ‘s’ command tells sed to stop looking for the standard slash and treat your chosen character as the field separator. This keeps your regex clean and prevents those annoying syntax errors.
🚀 Pro-Tip: You can use almost any character as a delimiter, even something like an exclamation point, if your string is really messy.
Linux Tips & Tricks | © ngelinux.com | 7/28/2026
