sedcaptureregexp-replacebrackets

Sed - Cannot capture and replace with curly brackets in a file


I would like to capture and replace with sed the following pattern :

{{/tagName}}} to {{/tagName}} }

But I cannot figure it out

I have tried

sed 's/({{\/.*}})/\1 }/g'

But it does not work. It does not capture and the blank space does not work in the 2nd part. Any idea? Thanks

UPDATE : To be more concise, the question is If I have to replace this pattern in a file with the option -i, how should I do ?

 sed -i 's/({{\/.*}})/\1 }/g' ./temp.txt

Solution

  • Or if you'd like BRE syntax, you could do it too. It would be rare case when they are more compact.

    $ sed  's/{{[^{}]\+}}/& /' <<< '{{/tagName}}}'
    {{/tagName}} }
    

    & in replacement the string represents full match of a the regexp part.

    EDIT: to replace all occurrences if file you can use

    sed -i 's/{{[^{}]\+}}/& /g' ./temp.txt