代码之家  ›  专栏  ›  技术社区  ›  teraspora

如何转义搜索中的字符`<`和`>',并替换传递给sed的字符串?

  •  0
  • teraspora  · 技术社区  · 5 年前

    我想替换 <title> 具有 <title>FRED ,使用 sed . 我试过下面的方法,但没有成功。

    19:46: scratch $ sed -i '/<title>/<title>FRED/' index.html
    sed: -e expression #1, char 10: unknown command: `<'
    ======================================================================================================================
    19:47: scratch $ sed -i '/\<title>/<title>FRED/' index.html
    sed: -e expression #1, char 11: unknown command: `<'
    ======================================================================================================================
    19:48: scratch $ sed -i "/\<title>/<title>FRED/" index.html
    sed: -e expression #1, char 11: unknown command: `<'
    

    那么,我该如何逃脱角色 < > 正确地?

    或者是我没有得到的其他东西?

    1 回复  |  直到 5 年前
        1
  •  2
  •   chepner    5 年前

    您尚未指定命令。你大概想要替换命令

    sed -i 's/<title>/<title>FRED/' index.html

    没有 s , sed 认为 /<title>/ 是命令的地址 < (不存在于 塞德 ).

    推荐文章