Created
February 15, 2016 19:50
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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