[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Omaha.pm] [olug] Character Removal



Carl Lundstedt wrote:
1...2...3...4...I smell a scripting war!!!

Guilty!

Obi-Wan wrote:
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

Overly bloated? Instead of

  sed -e

use

  perl -ple

and escape any parens outside of []'s.

Now sed and perl do the exact same thing in your examples.

So when specifically hunting parens I concede sed is less line-noisy. But "overly bloated"? Really? -poke- -laugh-

j
Omaha Perl Mongers: http://omaha.pm.org