regex - I'm matching a string and want to return the next three lines after the match -



regex - I'm matching a string and want to return the next three lines after the match -

i'm matching string , want homecoming next 3 lines after match. know $_ homecoming line i'm not sure look utilize homecoming next 2 lines in file have. here code have:

open $fh, '>', "${file}result.txt" or die $!; $fh->print("$file\t$_\n"); print "$_\n";

thanks in advance help , not making much fun.

keeping simple:

while (<$infile>) { if (/regex/) { $outfile->print($_); $outfile->print($infile->getline) 0 .. 1; } }

the io::handle methods nice couple of reasons. $infile->getline <>, ever grabs 1 line (whereas <> homecoming lines in list context). doesn't clobber $_ or warn @ end of file (although latter behavior desirable).

regex string perl line match

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -