-1

I need to remove all the text between the charcters: { and } in a phrase like:

the car {is} black {and} big

I run the Linux command:

sed -i 's/{.*}//g' myfile.txt

But the result is: the car big instead of what I wanted: the car black big. The regex found the biggest enclosing curly brackets and removed the text between the, but I wanted to treat every closure singularly. Is there a regex expression that can do the job?

Thanks in advance

Carlo Benussi
  • 165
  • 1
  • 14

1 Answers1

0

This line should help:

sed 's/{[^}]*}//g'

The regex .* does greedy match, it will match the first { till the last } in your input.

Kent
  • 189,393
  • 32
  • 233
  • 301