Sed, matching nested brackets and deleting

  1. The problem statement, all variables and given/known data:
    I have to write a script using sed, which delete everything between curly brackets and the brackets themself. The brackets might be nested.

The input-file is:

aaa { bbb ccc { ddd eee } fff { ggg hhh } iii jjj } kkk { lll mmm } nnn ooo ppp

The output-file should be:

aaa kkk nnn ooo ppp

  1. Relevant commands, code, scripts, algorithms:
    The script should be written in sed.
    Use of the pattern/hold space should be used economically, because for larger files the script still has to be usable.

  2. The attempts at a solution (include all code and scripts):

I have tried a few things but usually only can delete the first pair of brackets.

  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

University Gent, Gent, Belgium, Peter Dawyndt and C002718

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

An algorithm:

1) If pattern space (PS) contains an opening curly brace (OCB), substitute an OCB, followed by any other character other than an OCB and closing curly brace (CCB) any number of times, followed by a CCB, with null string globally. If not, stop processing the PS and output it.
2) Go to 1.

Convert it into a sed script and let us know.

First, post the solution where you can delete the first pair of brackets and see if you got that logic right.

Once you get that logic right, you can figure out how to delete the other ones.