sed to Delete Only Parentheses and Their Contents

Bismillahirrahmanirrahim.

sed ‘s/([^)]*)//g’

Before

*) this is the content of /var/log/apt/history.log on a Debian family OS

After

Explanation

The above sed says “match any char but ‘)’ ” started with a ‘(‘ ended with a ‘)’. That is the purpose of ‘[^)]’ negation to ‘)’ character and a ‘*’ means “any number of any char”.

Credit

Big thanks to potong for his StackOverflow answer.

Reference

http://stackoverflow.com/a/9857007


This article is licensed under CC BY-SA 3.0.