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

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re: Perl in one line
by shmem (Chancellor) on Nov 08, 2007 at 13:22 UTC
    cat file | grep -e str1 -e str2

    You've earned merlyn's useless use of cat award.

    grep -e '(str1|str2)' file

    --shmem

    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: Perl in one line
by toolic (Bishop) on Nov 08, 2007 at 13:50 UTC
    Others have provided possible solutions to your question.

    If you are familiar with unix and are just ramping up with Perl, you may find this to be helpful: UNIX 'command' equivalents in Perl.

Re: Perl in one line
by mwah (Hermit) on Nov 08, 2007 at 12:57 UTC
    cat file | grep -e str1 -e str2

    I'd think there are at least 10 different and reasonable versions of the above command possible in Perl, one would sth. read like:

    perl -ne 'print if /str1/ || /str2/' file

    Addendum: To use this under Windows, please replace the quotes, e.g.:

    C:\> perl -ne "print if /str1/ || /str2/" file

    Regards

    mwa

Re: Perl in one line
by Your Mother (Archbishop) on Nov 08, 2007 at 12:20 UTC

    That's easy. It's listed under section 3, problem 2 of the Teacher's Edition of "The Guide to Perl."

      sorry, but I'm not familiar with that site so well :-( - where can I found/see the Teacher's Edition of "The Guide to Perl." ? Thanks

        It was a gag. I was just horsing around because your question sounds like homework and you provided no code to show what you've tried. I should have included this: How (Not) To Ask A Question.

Re: Perl in one line
by KurtSchwind (Chaplain) on Nov 08, 2007 at 14:28 UTC
    Assuming this isn't for some perl class and is a genuine perl/unix question:
    grep -e str1 -e str2 file
    is one line. You don't need the cat.
    --
    I used to drive a Heisenbergmobile, but every time I looked at the speedometer, I got lost.
Re: Perl in one line
by Zen (Deacon) on Nov 08, 2007 at 15:12 UTC
    Monks, the motivation behind replacing unix commands with perl commands could be because the person is using windows. It's clear the person knows how to get what they want on unix, cat or no cat.