简体   繁体   中英

Using sed to replace the matching part of a line

I have this line in a test.txt file. And I just want to replace part of it, which is "location="http://adcgen07.us.oracle.com:7777/". The whole line is:

    <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 -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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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