美文网首页
sed 替换方括号[]

sed 替换方括号[]

作者: 苦咖啡JerryKFC | 来源:发表于2022-02-22 20:51 被阅读0次

    用 sed 替换字符串中的方括号[],比如将 a[bc]d 替换成 a_bc_d,需要执行:

    echo a[bc]d | sed 's/[][]/_/g'
    

    sed手册 里有这么一段:

    Most meta-characters lose their special meaning inside bracket expressions:
    ‘]’
      ends the bracket expression if it’s not the first list item. So, if you want to make the ‘]’ character a list item, you must put it first.
    
    在方括号表达式中大部分元字符失去了原来的意义:
    ‘]’
      如果它不是列表中的第一个项,则它表示结束方括号表达式。 所以,如果你想让‘]’字符成为列表项,你必须把它放在第一位。
    

    相关文章

      网友评论

          本文标题:sed 替换方括号[]

          本文链接:https://www.haomeiwen.com/subject/wbfnlrtx.html