in reply to Re: Write a file if grep finds a pattern?
in thread Write a file if grep finds a pattern?
use strict; use warnings; my $returncode; $returncode = 0; open (my $IN,"<c:/temp/logbook.log") || die "can not open datei: $!"; while(<$IN>){ if( /error/i ){ print; $returncode++; print "$returncode\n"; } } if ( $returncode == 0 ){ my $file = '/temp/ok.txt'; open FILE, '>', $file or die "Kann Datei $file nicht zum Schreiben +oeffnen: $!\n"; print FILE "ok!\n"; close FILE; } close $IN;
Thanks
MH
|
|---|