Text Processing (Grep/Sed/Awk)
Stop letting variable whitespace ruin your sed expressions
🧩 The Challenge
You ever try to script a quick config change with sed, only for it to fall over because your path variable has a forward slash in it? I spent forty minutes debugging a broken Apache config once because I kept escaping slashes like a maniac until I finally snapped.
💡 The Fix
Just stop using forward slashes as delimiters and switch to something sed doesn’t care about, like a pipe or a colon. It makes your one-liners actually readable and saves your sanity.
sed -i 's|/var/www/html|/opt/web/root|g' /etc/httpd/conf/httpd.conf
⚙️ Why It Works
By changing the delimiter to a pipe character, you remove the need to escape every single path separator inside your command. Any character that isn’t a space or a backslash works, though I usually stick to pipes or hashes.
🚀 Pro-Tip: Use this for anything involving URL strings or full file paths to avoid the inevitable backslash hell.
Linux Tips & Tricks | © ngelinux.com | 11/29/2026
