[sf-perl] double filter (but short)
Vicki Brown
vlb at cfcl.com
Tue Jul 1 08:30:41 PDT 2008
I have a text file, with lines like this:
carrot: backwards
banana: ran
apple: sentences
I am using a very short, sweet bit of Perl to reverse the lines
perl -e 'print reverse <>'
resulting in
apple: sentences
banana: ran
carrot: backwards
I also want to convert the part before each initial colon, so the result is
_apple_: sentences
_banana_: ran
_carrot_: backwards
I can do this with
perl -e 'print reverse <>' |
sed 's/^\([^:]*\):/_\1_:/'
or with all Perl
perl -e 'print reverse <>' |
perl -pe 's/^([^:]*):/_$1_:/'
but I haven't been able to come up with a tidy way to combine the two
filters into one call to perl. (s//)(reverse) or (reverse)(s//).
Possible?
--
- Vicki
ZZZ
zzZ San Francisco Bay Area, CA
z |\ _,,,---,,_ Books, Cats, Tech
zz /,`.-'`' -. ;-;;,_ http://cfcl.com/vlb
|,4- ) )-,_. ,\ ( `'-' http://cfcl.com/vlb/weblog
'---''(_/--' `-'\_) http://twitter.com/vlb
More information about the SanFrancisco-pm
mailing list