Monday, October 24, 2022

[SOLVED] Trying to escape a / for sed on ubuntu

Issue

I am trying to use sed to replace a path in a file.

sudo sed 's/a/b/g' -i /tmp/test

However the variable is

a = /var/lib and 
b = /data/lib

How do I escape the slash?


Solution

The character just after the s command doesn't need to be a /. When working with paths, I use :, as in:

sudo sed 's:a:b:g' -i /tmp/test


Answered By - mouviciel
Answer Checked By - Katrina (WPSolving Volunteer)