assuming you would want to process all log files in a directory and extract line lines with keyword ..
$keyword = "your keyword here"; open hanw,"<" , "output.txt" or die "could not open output file $!"; opendir(hand,$dirpath); #replace with your DIR @files = readdir(hand); closedir(hand); foreach(@files){ if(/\.log$/i) { + #if the filename has .log at the end push(@logfiles,$_); } } $nooffiles = @logfiles; $fileindex=0; while ($fileindex <$nooffiles ) { open hanr ,">", "$logfiles[$fileindex]" or die "could not open logfile + .. $!"; while (<hanr>) { if ($_ =~ /$keyword/ ) { print hanw ; #last; --if it will occur only once } } close hanr; $fileindex++; } close hanw;
if you are sure it will occur inside a block then use the code block using flip flop operator as suggested above
if (/$start/i .. /$end/i) # where start and end are your start and end keywords
In reply to Re: Extracting a block of text between start and end point
by sandy105
in thread Extracting a block of text between start and end point
by shonurulez
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |