Skip to content

Instantly share code, notes, and snippets.

@b4hand
Created February 15, 2016 19:50
Show Gist options
  • Select an option

  • Save b4hand/9e7132febf82ff7d8b88 to your computer and use it in GitHub Desktop.

Select an option

Save b4hand/9e7132febf82ff7d8b88 to your computer and use it in GitHub Desktop.
Merges multiple sets of output from the `uniq` command into a single output
#!/usr/bin/env perl
use strict;
use warnings;
use List::Util qw(max);
my %counts;
sub log10 {
my ($n) = @_;
return log($n) / log(10);
}
while (my $line = <>) {
chomp($line);
my @fields = split /\s+/, $line;
$counts{$fields[2]} += int($fields[1]);
}
my $max_value = max(values(%counts));
my $digits = int(log10($max_value)) + 1;
while (my ($key, $value) = each %counts) {
printf " %${digits}d %s\n", ($value, $key);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment