You were close. Sed's pattern matching is greedy though, so the regex
s/\[.*\]//g
will match everything from the first opening bracket to the last closing one. What you need is to replace the '.' (which means 'any character'), with 'not closing bracket', that is [^]]:
Thanks a lot! you guys are great!
The perl one is working exactly what I needed.
But for sed I am becoming fool when trying to to do it for (). Following are not working:
sed 's/(^*)//g'
sed 's/\((^))*\)//g'
Do we need to handle () in a different way, I guess we don't need to negate () like we need to do for [].
The difference is that '[' and ']' are metacharacters in regexp.
[^a] means all characters but not 'a'. So literal '[' or ']' needs to be escaped as \[, resp. \].
With parens its actually simpler:
sed 's/([^)]*)//g'
Since you don't have to escape them. But it's the same logic -- you do use the [^)] to match all characters but not ')'. If you allowed ')' to be matched, it would greedily eat the whole thing between first ( and last ). Not what you want here.