Remove string between two delimiter, inclusively
bash, sed
Solution
Indeed, sed is greedy. But you can do:
sed 's/(def[^)]*)//gi'
Note that not all sed accept the `i` flag, so you may need to do:
sed 's/([dD][eE][fF][^)]*)//g'
Problem
In a bash script, what utility and how do I go about removing text between two strings, inclusive of the stings. Original text: ``` (ABC blah1)blah 2(def blah 5)blah 7)(DEF blah 8)blah 9 ``` I would like to remove all text between '(def' and the next ')'. So my desired output would be: ``` (ABC blah1)blah 2blah 7)blah 9 ``` It would be preferable to have the search be case insensitive... in the above example, it found and remove '(def...)' and '(DEF...)' I have tried: ``` echo "(ABC blah1)blah 2(def blah 5)blah 7)(DEF blah 8)blah 9" | sed 's/(def.*)//gI' ``` but the output is: ``` (ABC blah1)blah 2blah 9 ``` I think this is because '.*' is greedy in sed. Any ideas how I can format my sed search string? Is sed even the best util for this? I am running this from a bash script so anything basic util avail via bash will do.