[olug] Character Removal

stan at srcproductions.com stan at srcproductions.com
Sat Oct 20 06:45:00 UTC 2007


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 ).

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


Quoting Obi-Wan <obiwan at jedi.com>:

>> I'd like to remove all characters between a '(' and the second ')'.
>
> Perl has its uses, but is overly bloated for such a simple operation.
> Sed(1) does a wonderful job of this sort of thing.  Assuming you want
> to keep the first and last parentheses:
>
> # echo "abc (asdf) asdf (asdf) 1234 (xyz) 67" | sed -e 's/([^)]*)[^)]*)/()/'
> abc () 1234 (xyz) 67
>
> If you don't want to keep those parens, then drop the last pair from
> that sed command:
>
> # echo "abc (asdf) asdf (asdf) 1234 (xyz) 67" | sed -e 's/([^)]*)[^)]*)//'
> abc  1234 (xyz) 67
>
> --
> 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
> _______________________________________________
> OLUG mailing list
> OLUG at olug.org
> http://lists.olug.org/mailman/listinfo/olug
>







More information about the OLUG mailing list