繁体   English   中英

使用sed命令替换一行上的字符串

[英]Replace string on a line using sed command

我在文件中有以下内容

return o.baseUrl="http://info.example.com/api/v1/",a.init=t,o.login=e(o.baseUrl+"login",{email:"@email",password:"@password"}

我想更换info.example.comapi.example.com

目前我正在使用

sed -i "s/^info\.example\.com.*$/api.example.com/g" /var/html/www/index.js

但这是行不通的。 我对正则表达式了解不多。 有人可以帮我吗?

sed您可以提供要替换的确切表达式。

sed 's/info\.example.com/api.example.com/g' file

^锚在行的开头匹配info\\.example\\.com

锚对您而言毫无用处。 从模式中删除^$

sed -i 's/info\.example\.com/api.example.com/g' /var/html/www/index.js

更多关于锚这里

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM