Quote:
Originally Posted by digitalrg
Thank you sethcoop.. but can you please tell me how to print 10 lines below the occurance of word "total" please help.....
Thanks
|
Here is the code to print the number of lines below your search... you can change the variable $lines to be how many lines you want to print after the word total.
Hope this helps!
Code:
#!/usr/bin/perl
$lines = 10;
$x = $lines;
open(F, "file.txt") or die "cannot read file";
while(<F>) {
chomp;
$my_line = "$_";
if ("$x" < "$lines") {
print "$my_line\n";
$x++;
}
if ("$my_line" =~ "total") {
$x = 0;
}
};