in reply to How to read lines between specific character

if by "between" you mean last occurence between:
#!/usr/bin/env perl open F, "</tmp/fff"; $b=$between=$energy=0; while (<F>) { if (/energy/i) { $energy++; $between=$b; } elsif ($energy) {$b++} } print $energy, "/", $between;

Replies are listed 'Best First'.
Re^2: How to read lines between specific character
by MishaMoose (Scribe) on Nov 12, 2010 at 15:01 UTC

    if you need to track the number of lines between MULTIPLE 'energy lines' then a modification to the above like this might be in the right direction ...

    #!/usr/local/perl5/bin/perl open F, "<./fff"; $b=$energy=0; @between = (); while (<F>) { if (/energy/i) { $between[$energy]=$b; $energy++; $b = 0; } else {$b++} } $between[$energy]=$b; my $i; printf("Before Energy 1 : %3d lines occur\n",$energy,$betwee +n[0]) if ($between[0] > 0); for($i = 1; $i < $energy; $i++) { printf("Between Energy %3d and %3d: %3d lines occur\n",$i,$i+1,$betwe +en[$i]); } printf("After Energy %3d : %3d lines occur\n",$energy,$betwee +n[$energy]);
    Misha/Michael - Russian student, grognard, bemused observer of humanity and self professed programmer with delusions of relevance

      thankx...i might need this logic in the next part of my code :) thankx

Re^2: How to read lines between specific character
by AG87 (Acolyte) on Nov 13, 2010 at 18:47 UTC

    thankx alot...it actually worked..... :)

Re^2: How to read lines between specific character
by AG87 (Acolyte) on Nov 13, 2010 at 18:52 UTC

    @fisher...thankx 4 help

Re^2: How to read lines between specific character
by AG87 (Acolyte) on Nov 13, 2010 at 19:09 UTC

    @fisher...thankx for help....it actually worked....thankxalot :)

Re^2: How to read lines between specific character
by AG87 (Acolyte) on Nov 13, 2010 at 18:44 UTC

    thank you soo much.....it actually worked...thankalot