0

I would like to replace any

...
title = {{ some text }}
...

to

...
title = { some text }
...

Indeed, I want to replace double curly braces to one (in windows 7).

I came up sing sed but apparently sed in windows does not work properly. Here is a simple test that shows the problem. I want to replace double curly braces {{ with one { . Here what I am trying to do:

sed "s/{{/{/g" file.txt

However I get this error

sed: 1: "s/": unterminated substitute pattern

I have seen this but apparently it doesn't work in Windows os: sed find and replace with curly braces

Any idea how to do this?

Community
  • 1
  • 1
A.GH
  • 123
  • 7
  • What sed version do you use, is it in `CYGWIN` or `sed for Windows`. I have no problem to run your command `sed "s/{{/{/g" file.txt` in cygwin. – BMW Feb 12 '14 at 00:05
  • @BMW I was using `sed for Windows` and it seems it doesn't work with `{`. After your comment I installed `CYGWIN` and it works fine. Maybe you want make your comment as an answer then I can accept it. – A.GH Feb 12 '14 at 10:36
  • sure, updated with answer it. – BMW Feb 12 '14 at 10:40

3 Answers3

2

Try escaping them:

sed "s/\{\{/{/g" file.txt
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • I've tried it as well. this is the error I get: sed: 1: "s//": unterminated substitute in regular expression – A.GH Feb 11 '14 at 20:20
  • doesn't work. the error I get : sed: 1: "'s//": invalid command code ' – A.GH Feb 11 '14 at 20:22
0

with ?

sed "s/\(\([{}]\)\2\)/\2/g"

to avoid multiple { and } in pattern and associate interpretation. (work for { and } at once)

NeronLeVelu
  • 9,908
  • 1
  • 23
  • 43
  • still it doesn't work with `sed for Windows` but it works fine with `CYGWIN`. – A.GH Feb 12 '14 at 10:38
  • --posix option is available on windows (not sur, documentation of GNU sed i found does not specify this ) ? also try -e bedore the string of command – NeronLeVelu Feb 12 '14 at 12:08
  • thanks for your comment. Using -e indeed solves the problem in `sed for Windows`. However, I opted for CYGWIN which seems considering my problem is more consistent with the Linux version of sed command. – A.GH Feb 12 '14 at 22:41
0

What sed version do you use, is it sed in CYGWIN or sed for Windows. I have no problem to run your command sed "s/{{/{/g" file.txt in cygwin.

If you run the sed from a windows version sed for windows, seems it doesn't work with {. Try in CYGWIN.

BMW
  • 42,880
  • 12
  • 99
  • 116
  • Also an alternative answer would be the one which is given by @NeronLeVelu in a comment to his answer (i.e. using -e option for `sed for Windows`) – A.GH Feb 13 '14 at 08:02