简体   繁体   English

使用sed替换行的匹配部分

[英]Using sed to replace the matching part of a line

I have this line in a test.txt file. 我在test.txt文件中有此行。 And I just want to replace part of it, which is "location="http://adcgen07.us.oracle.com:7777/". The whole line is: 我只想替换它的一部分,即“ location =“ http://adcgen07.us.oracle.com:7777/”。整行是:

    <soap:address xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" location="http://adcgen07.us.oracle.com:7777/soa-infra/services/default/TestProducer1/client"/>

The regular expression I wrote for the matching string is 我为匹配字符串编写的正则表达式为

    \blocation="http\b.*\b:777[0-9]

But if I use sed to replace the string, it will give me this following error. 但是,如果我使用sed替换字符串,它将给我以下错误。

    sed -i .bak 's/\blocation="http\b.*\b:777[0-9]/hello/' test.txt
    sed: -e expression #1, char 1: unknown command: `.'

Thanks in advance for your help. 在此先感谢您的帮助。

尝试这个:

sed -i ".bak" "s/location=\"http:\/\/.*:777[0-9]/hello/" test.txt

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

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