开发者

sed code to match http://www.domain.com/ and replace with just a / in all files in a directory

I've been searching for this answer for three hours now and I still can't get anything to work. When I run things like this:

 sed -i 's/http\:\/\/www\.domain\.org\//\//g checkout_*.php

It drops me into another command line (sorry, I'm very new to sed).

I just want to cd to a dir, grep the di开发者_JAVA百科r to see if the string is there then run a replace so I can change my paths from absolute to relative.


You need to close your '. You can also make your command cleaner by using a different sed delimiter to / so that you don't have to escape all those forward slashes in your URL. For example, you can use !, as shown below:

sed -i 's!http://www\.domain\.org/!/!g' checkout_*.php


You just appear to be missing the closing '

sed -i 's/http\:\/\/www\.domain\.org\//\//g' checkout_*.php

Should do what you want ok. But I'd warn you against doing the -i switch without first doing a dry run.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜