Shell – Deleting parentheses in shell script

awksedshell-scripttext processing

I would like to create mechanism to delete parentheses, or parentheses and the text between them. For example:

before:

text0 text1 text2 (text3 text4)

after:

text0 text1 text2 text3 text4

or:

text0 text1 text2

I would like to test both options and other type of brackets but I'm not sure what tool should I use, Awk or Sed or maybe something else? I would be grateful for any advice.

Best Answer

The other half of your question, deleting just the parentheses (but not the text between them):

echo 'text0 text1 text2 (text3 text4)' |
   sed 's/[()]//g'

Output:

text0 text1 text2 text3 text4
Related Question