This:
#!/usr/bin/perl use strict; use Socket; unlink for </tmp/prefix.*.ips>; my %prefixes; while( <> ) { while( /((\d+)\.\d+\.\d+\.\d+)/g ) { open my $f, '>>', "/tmp/prefix.$2.ips"; $prefixes{$2}++; print $f inet_aton($1), "\n" } } for ( sort {$a <=> $b} keys %prefixes ) { my %addresses; open my $f, '<', "/tmp/prefix.$_.ips"; while( <$f> ) { chomp; $addresses{$_}++ } printf "%-20.20s => %d\n", inet_ntoa($_), $addresses{$_} for sort {$ +a <=> $b} keys %addresses } unlink "/tmp/prefix.$_.ips" for keys %prefixes __END__ 64.233.169.17 => 1 64.233.169.18 => 1 75.101.152.211 => 2 85.17.189.130 => 4 127.0.0.1 => 8 174.129.112.136 => 1 174.129.233.130 => 1
should work Ok (tested here with far less than a billion IPs). If you think it's still hogging the memory, you can just substritute
while( /((\d+)\.\d+\.\d+\.\d+)/g ) {
for
while( /((\d+\.\d+)\.\d+\.\d+)/g ) {
and be done with it.
[]s, HTH, Massa (κς,πμ,πλ)

In reply to Re: Working with large amount of data by massa
in thread Working with large amount of data by just1fix

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.