[olug] Character Removal

Obi-Wan obiwan at jedi.com
Sun Oct 21 17:50:19 UTC 2007


>> # echo "abc (asdf) asdf (asdf) 1234 (xyz) 67" | sed -e 's/([^)]*)[^)]*)/()/'
>> abc () 1234 (xyz) 67
>
> OK I'd probably decipher this when I'm awake but just in case I don't  
> how would you get this as an output:
> 
> abc  1234 67
> 
> I want to delete multiple occurrences of things between ( and ).

So do you or do you not want the "asdf" between the first and second
pairs of parens?  To delete everything inside and including any pair
of parens:

# echo "abc (asdf) asdf (asdf) 1234 (xyz) 67" | sed -e 's/([^)]*)//g'
abc  asdf  1234  67

To delete from the first ( to the second ), and then the contents
of every pair of parens thereafter, I'd just pipe the two sed commands
together.  It'll be easier than trying to come up with a monster
regex that will do both.

> Why doesn't '/first_character/,/second_character/,d' work? Every  
> online help I can find suggest it should work.

Hmm... I'm not familiar with that syntax in sed.  Sorry.

-- 
Ben "Obi-Wan" Hollingsworth                             obiwan at jedi.com
   The stuff of earth competes for the allegiance I owe only to the
     Giver of all good things, so if I stand, let me stand on the
       promise that You will pull me through.  -- Rich Mullins



More information about the OLUG mailing list