I'm still not sure what $line or "45454 matches" you're referring to.

I'm guessing you do want the lines that end in "matches)", but want to do something different with those, like make a list, sorted by number of matches. In that case, the basic logic would be like this:

while (<STDIN>) { if (/(\d+) matches\)/) { # keep this in a list we'll sort later push @list, [ $1, $_ ]; } else { # same case as before, write it to the log print LOG; } } # Now print out the list we built before in sorted order foreach (sort { $a->[0] <=> $b->[0] } @list ) { print $_->[1]; }
You can adapt the basic logic in the loop without using more advanced data structures like I just did, but that's a pretty easy way to do it. This will keep all of the file in memory, so hopefully your file is not too huge.

The data structure that gets built up in @list is an array of arrays; in other words, each element of @list is an anonymous array that gets pushed into each time. Each of those arrays has two elements: the number of matches, and the line itself. Later, the loop works calls sort on the number matches (element 0), and the print outputs the line (element 1). To learn more about those data structures, look at perlreftut and perldsc.


In reply to Re (3): Parsing cisco log file by VSarkiss
in thread Parsing cisco log file by routedude

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.