[sf-perl] double filter (but short)

Steve Fink sphink at gmail.com
Tue Jul 1 18:13:14 PDT 2008


The reverse gets in the way, so I wouldn't bother with perl for it.
Use 'tac' instead.

Then you could do

  tac (filename) | perl -F: -lane 'print "__$F[0]__:$F[1]"'

On Tue, Jul 1, 2008 at 8:30 AM, Vicki Brown <vlb at cfcl.com> wrote:
> 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
> _______________________________________________
> SanFrancisco-pm mailing list
> SanFrancisco-pm at pm.org
> http://mail.pm.org/mailman/listinfo/sanfrancisco-pm
>


More information about the SanFrancisco-pm mailing list