OfficeLinebacker has asked for the wisdom of the Perl Monks concerning the following question:

Esteemed Monks,

I ended up using a bunch of sed commands to alter a file I had into a format that I ultimately used with grep -f.

I'd like to learn more about how to use perl one-liners to do the same thing. I did a SuperSearch, but can't seem to figure out how to isolate 'sed' alone from 'used','uninitialised', etc.

Any recommendations on this? Or should I just stick with sed for quickie one-liners?

Thanks,

T.

  • Comment on perl programs from the command line in the manner of sed?

Replies are listed 'Best First'.
Re: perl programs from the command line in the manner of sed?
by kvale (Monsignor) on Apr 21, 2006 at 15:52 UTC
    You may wish to try s2p, the sed to perl script, to get an idea of how to translate. Also check out perlrun for a number of useful runtime switches that make creating one liners much easier.

    -Mark

Re: perl programs from the command line in the manner of sed?
by davido (Cardinal) on Apr 21, 2006 at 16:00 UTC

    The Perl documentation includes perlrun, which has most of the info you'll need, but it might not be enough of a "tutorial" style to really get you started. I wrote a node a little over a year ago that worked out to be a sort of crash course in one-liners; certanly not complete, but enough to get you started. You can find it here: Re: One Liners.


    Dave

      Oh man, great Node! Thanks!

      Mark, thanks to you, too!

      T.

Re: perl programs from the command line in the manner of sed?
by blazar (Canon) on Apr 21, 2006 at 16:02 UTC

    You should check perldoc perlrun, in particular you're likely to be interested in -n, -p, or the "chomping versions" -ln, -lp, possibly with inline modifying, -i and/or with changing the input record separator...

    As for PM's Super Search, try with "oneliners" et similia, although the results won't be focused on conversions from sed, they're likely to solve tasks similar to the ones you're interested in.

      Does your name rhyme with "Quasar" or "blazer?"

      Ok, so I see the search term I should be focusing on is oneliner and its derivatives...thanks!

      Also, s2p exists on my system! (seems relatively rare comapared to some of the other suggestions I've gotten, mostly re: modules). Time to "man up" on that!

      Thanks for treating a newbie so kindly.

Re: perl programs from the command line in the manner of sed?
by ghenry (Vicar) on Apr 23, 2006 at 20:17 UTC

    Good ones at Favourite One-liners?

    HTH.

    Walking the road to enlightenment... I found a penguin and a camel on the way.....
    Fancy a yourname@perl.me.uk? Just ask!!!