Sed or perl Delete outer parentheses only if the first inner word matches

Using GNU sed, I need to remove paste phrases like (click here ....), including parens. The text following click herechanges, but I need to remove all the outer parentheses.

I tried many options on the following, but I can't seem right:

sed -e 's/\((click here.*[^)]*\)//'

EDIT Stupidly, I did not notice that in the middle of the line in parentheses a line often appears, so sedit probably won't work. Example:

(click here to
enter some text)
+3
source share
3 answers

With perl, you can run:

perl -00 -pe "s/\(click here [^)]*\)//g" inputfile > outputfile

, (click here anychar but '(' ), .

+2

, , - :

sed -e 's/(click here [^)]*)//'
+3

Here's another approach sedthat stores full input in a hold buffer:

# see http://austinmatzko.com/2008/04/26/sed-multi-line-search-and-replace/
echo '
()
(do not delete this)
()
(click here to
enter some text)
()
' | 
sed -n '1h;1!H;${;g;s/(\([^)]*\))/\1/g;p;}'
+1
source

All Articles