This loops through the lines, getting the Fanout value from the lines with INT_NET, and if it's equal to or greater than the maximum Fanout value so far, it saves that line along with its Fanout value as a 2-element array reference in the array @lines.

Once it's done, it has the largest Fanout value in $max and all the lines with that value (along with some other lines, possibly) as the first elements in the array @lines. The map/grep statement goes through those, grepping for the ones with the $max Fanout value and then using map to pull out the line itself and pass that to print.

#!/usr/bin/env perl use 5.010; use warnings; use strict; my $max = 0; my @lines; # 2D array, each element holding a line and its Fanout val +ue while (<DATA>){ if (/(\d+)\s+INT_NET/ and $1 >= $max ){ push @lines, [$_,$1]; $max = $1; } } print for map { $_->[0] } grep { $_->[1] == $max } @lines; __DATA__ Fanout Type Name -------------------------- 2 INT_NET Net : c_c Driver: c_pad 2 INT_NET Net : b_c Driver: b_pad 2 INT_NET Net : a_c Driver: a_pad 1 INT_NET Net : sum_c Driver: sum_1_SUM0_0 1 INT_NET Net : N_5 Driver: sum_1_CO0_i

Aaron B.
Available for small or large Perl jobs and *nix system administration; see my home node.


In reply to Re: Find maximum number in text file and copying its full statement in new text file? by aaron_baugher
in thread Find maximum number in text file and copying its full statement in new text file? by sumathigokul

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.