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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s