in reply to Write a file if grep finds a pattern?

Can't resist giving a shell solution, as it's shorter than the Perl solutions offered so far:
if grep -l error /temp/logbook.log > /dev/null then echo 'ok!' > /temp/ok.txt fi

Replies are listed 'Best First'.
Re^2: Write a file if grep finds a pattern?
by Anonymous Monk on Nov 19, 2010 at 11:41 UTC
    ?
    if( `grep -l error /temp/logbook.log > /dev/null`) `echo 'ok!' > /temp/ok.txt` }
      Let's say, you're asking the shell to run grep and discard the output, then collect the output, and if you say anything, you ask the shell to put something in a file, all to show your "Perl" program is as long as a shell one?

      It doesn't even work this way.

      But if you want to golf (if you have 'ack', shave off one character):

      grep error c:/temp/logbook.log&&echo 'ok!'>/temp/ok.txt
      Slapping backquotes on it to make it "Perl", still is two characters more.