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:
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.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]; }
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |