aasanchez
aasanchez

Reputation: 169

Replace windows path with linux path using sed in a file

I have one configuration file than i need change automatic with a script..

I try to use all options posible with

sed -i \"s/G:\\xampp\\www\\myweb/\/srv\/myweb\/public_html/g\" myfile.php

But i can not make this work, any help???

The solution must be using bash because is runing inside a huge script.. thanks for any advice

Upvotes: 0

Views: 1153

Answers (3)

SLePort
SLePort

Reputation: 15461

Try to unescape the quotes surrounding the command and escape \ like this:

sed -i "s/G:\\\xampp\\\www\\\myweb/\/srv\/myweb\/public_html/g" file

Upvotes: 1

Sundeep
Sundeep

Reputation: 23667

$ echo 'foo G:\xampp\www\myweb bar' | sed 's#G:\\xampp\\www\\myweb#/srv/myweb/public_html#g'
foo /srv/myweb/public_html bar

Use single quotes and use a delimiter different than / that doesn't appear in search/replacement terms (any character other than \ and newline characters can be used as delimiter)

\ is meta character, use \\ to represent it literally

Upvotes: 0

randomir
randomir

Reputation: 18687

This will do it:

sed 's|G:\\xampp\\www\\myweb|/srv/myweb/public_html|g' -i myfile.php

We're using | as delimiter in sed search command (instead of the default /) to avoid escaping of /, and a single quotes around everything to avoid double escaping of \.

Upvotes: 1

Related Questions