[ale] here's one for the script wizards
fletch at phydeaux.org
fletch at phydeaux.org
Wed Feb 10 12:05:14 EST 2010
>
>> Sorry, I wasn't specific enough. I'm looking to separate all the
>> parenthesized words from the non-parenthesized:
>>
>> input: foo (bar) ice cream (brown) sky is blue (airplane flies) just
>> flies
>>
>> output:
>> foo ice cream sky is blue just flies
>> (bar) (brown) (airplane flies) --- with or without parenthesis, it
>> doesn't matter.
>
> Presuming the parens aren't nested
>
> $ echo 'foo (bar) ice cream (brown) sky is blue (airplane flies) just
> flies' | perl -lne
> 'my(@n, at p);my at d=m{(\(?[^()]+\)?)\s+}g;push@{$_%2==0?\@n:\@p},$d[$_]for
> 0..$#d;print join(" ", at n);print join(" ", at p);'
> foo ice cream sky is blue just
> (bar) (brown) (airplane flies)
Bah, messed up the regex and it drops the last word. Slightly tweaked
version works better.
echo 'foo (bar) ice cream (brown) sky is blue (airplane flies) just flies'
| perl -lne
'my(@n, at p);my at d=m{(\(?[^()]+\)?)(?:\s+|$)}g;push@{$_%2?\@p:\@n},$d[$_]for
0..$#d;print join(" ", at n);print join(" ", at p);'
foo ice cream sky is blue just flies
(bar) (brown) (airplane flies)
--
Fletch | "If you find my answers frightening, __`'/|
fletch at phydeaux.org| Vincent, you should cease askin' \ o.O'
| scary questions." -- Jules =(___)=
| U
More information about the Ale
mailing list