Take the 2-minute tour ×

I'm trying to find a way to delete the first match of a certain line, and not the last one. To explain this better, here is my file:

(Foo Bar)
Foo = B(ar)a(foo)r

My problem is that I'm trying to delete the () and the text within it. Here is my current code:

sed 's:(.*)::g'

But it outputs this:

Foo = Br

Instead of this:

Foo = Bar

How would this be done?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

* is greedy, and that will match till the last ).

sed 's:([^)]*)::g'
share|improve this answer
Thanks a lot, it worked. Gonna promote it as the answer when it will allow me. –  MiJyn Dec 8 '11 at 21:32
add comment

Your Answer


