【问题标题】:Sed replace string with another string wrong result [duplicate]Sed用另一个字符串替换字符串错误结果[重复]
【发布时间】:2019-12-03 16:27:06
【问题描述】:

我需要从下面的行中将../ 替换为./

<html xmlns:og="http://test.org/schema/"  xmlns:website="../test/ns/website" >

但是当使用命令时

sed -i 's+../+./+g' ./*

文件内容改为

&lt;html xmlns:og="htt.//test.o./sche./" xmlns:website="./te././website" &gt;

可能是什么问题。

【问题讨论】:

标签: linux sed command-line


【解决方案1】:

应该这样做:

echo "<html xmlns:og="http://test.org/schema/"  xmlns:website="../test/ns/website" >" | sed 's|\.\./|./|g'
<html xmlns:og=http://test.org/schema/  xmlns:website=./test/ns/website >

你需要转义.,否则它意味着任何字符。

这应该也可以: sed 's+\.\./+./+g'

【讨论】:

    猜你喜欢
    • 2011-12-21
    • 2015-01-17
    • 2020-01-12
    • 2019-10-14
    • 1970-01-01
    • 2019-05-14
    • 2014-09-17
    • 2013-12-03
    • 2019-12-13
    相关资源
    最近更新 更多