[英]Replace string on a line using sed command
I have following content in a file 我在文件中有以下内容
return o.baseUrl="http://info.example.com/api/v1/",a.init=t,o.login=e(o.baseUrl+"login",{email:"@email",password:"@password"}
I want to replace info.example.com
with api.example.com
我想更换info.example.com
与api.example.com
Currently I am using 目前我正在使用
sed -i "s/^info\.example\.com.*$/api.example.com/g" /var/html/www/index.js
But this is not working. 但这是行不通的。 I don't know much about regular expression. 我对正则表达式了解不多。 Can somebody help me on this ? 有人可以帮我吗?
在sed
您可以提供要替换的确切表达式。
sed 's/info\.example.com/api.example.com/g' file
^
anchor matches info\\.example\\.com
at the beginning of the lines. ^
锚在行的开头匹配info\\.example\\.com
。
Anchors are useless in your case. 锚对您而言毫无用处。 Remove the ^
and $
from your pattern: 从模式中删除^
和$
:
sed -i 's/info\.example\.com/api.example.com/g' /var/html/www/index.js
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.