in reply to Re: Printing th entire line with a keyword
in thread Printing th entire line with a keyword

Is there a way using grep?

Because the corresponding code in shell script is like grep "searchkeyword" $filetobesearched> $outputfile

Replies are listed 'Best First'.
Re^3: Printing th entire line with a keyword
by roboticus (Chancellor) on Dec 31, 2012 at 05:40 UTC

    It's even easier with grep. But in perl, grep wants to match against a list, so you'll be back to reading line-by-line:

    #!/usr/bin/perl use strict; use warnings print "<$_>\n" for grep {chomp; /(fox|wood)/} <DATA>; __DATA__ Now is the time for all good men to come to the aid of their party. The quick red fox jumped over the lazy brown dog. How much wood can a woodchuck chuck? If a woodchuck could chuck wood?

    This should give the same result. (Note: the chomp isn't required, but I wanted to match the output of the previous code, so I put it in.)

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

      Thank you :)