Ish
Ish

Reputation: 21

How to find and replace a file path (along with special characters) using SED command

How to find and replace a file path like a/b/c/d into x/y/z using sed command?

I tried sed -i -e 's/a/\b/\c/\d/x/\y/\z' file.txt but it did not work.

Upvotes: 0

Views: 168

Answers (1)

KamilCuk
KamilCuk

Reputation: 142080

Just use another separator for s command. You can use any character. Just / is the most popular one. I like @ or #. Then you have to escape that character.

sed 's@a/b/c/d@x/y/z@'

but it did not work

To escape / use \/ not /\. The \ needs to be in front of /. You could:

sed 's/a\/b\/c\/d/x\/y\/z/'

Upvotes: 1

Related Questions