in reply to Long list is long
If I were on a linux system, I'd try it this way. The perl takes almost no memory :)
#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11147822 use warnings; use Path::Tiny; path("/tmp/11147822.$_.txt")->spew( <<END ) for 1 .. 100; # FIXME for +testing only foo 73 bar 35 word 27 blah 23 END open my $fh, '-|', 'sort /tmp/11147822.*.txt' or die; # FIXME for your + file list open my $tosort, '|-', 'sort -n -k2' or die; <$fh> =~ /^(\w+)\s+(\d+)/ or die; my ($name, $value) = ($1, $2); while( <$fh> ) { if( /^(\w+)\s+(\d+)/ ) { if( $1 eq $name ) { $value += $2; } else { print $tosort "$name\t$value\n"; ($name, $value) = ($1, $2); } } } print $tosort "$name\t$value\n"; # be sure to print last one close $tosort or die;
Outputs:
blah 2300 word 2700 bar 3500 foo 7300
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Long list is long
by Chuma (Scribe) on Oct 30, 2022 at 15:18 UTC | |
by tybalt89 (Monsignor) on Oct 30, 2022 at 17:08 UTC |