sed find and replace with curly braces

后端 未结 2 638
野趣味
野趣味 2020-12-30 22:59

I am trying to use this command:

sed -i \'s#\\{test1\\}#test2#\' /example/myfile.txt

To replace instances of {test1} with

相关标签:
2条回答
  • 2020-12-30 23:25

    You aren't escaping the curly braces at all. In sed, the default regular expressions are BREs, where \{ and \} indicate a range expression. Since test1 isn't a range, your BRE is incorrect.

    To fix it, you can either drop the backslashes (braces aren't special in BREs) or keep it the same and tell sed to use EREs (-r flag with GNU sed, -E flag with BSD/MacOSX sed).

    0 讨论(0)
  • 2020-12-30 23:47
    sed -i 's#{test1}#test2#' /example/myfile.txt
    

    You don't need escape {}

    0 讨论(0)
提交回复
热议问题