在大型WordPress数据库中,我经常需要用活动url替换本地url。我可以在TextMate中完成,但它通常需要10+分钟才能完成。
基本上,我有一个10MB+ .sql文件,我想要:
查找:http://localhost:8888/mywebsite
和
替换为:http://mywebsite.com
之后,我将保存文件并将mysql导入到本地/实时服务器。我每周至少做3-4次,等待Textmate是一件痛苦的事情。使用grep/sed/awk有没有更简单/更快的方法来做这件事?
谢谢!
泰瑞
发布于 2011-09-26 21:26:53
sed 's/http:\/\/localhost:8888\/mywebsite/http:\/\/mywebsite.com/g' FileToReadFrom > FileToWriteTo
这是全局运行switch (s/) (/g)并用第二个URL替换第一个URL。正斜杠用反斜杠转义。
发布于 2011-09-26 21:25:07
kent$ echo "foobar||http://localhost:8888/mywebsite||fooooobaaaaaaar"|sed 's#http://localhost:8888/mywebsite#http://mywebsite.com#g'
foobar||http://mywebsite.com||fooooobaaaaaaar
如果要就地替换(在原始文件中进行更改)
sed -i 's#http://.....#http://mysite#g' input.sql
发布于 2013-08-26 04:54:40
您不需要更换http://
sed "s/localhost:8888/www.my-awesome-page.com/g" input.sql > output.sql
https://stackoverflow.com/questions/7555707
复制相似问题