#!/usr/bin/perl my %counts = (); my %list = (); my $keys; my $total; my $in = "BIGFILE.out.gz"; my $out_min = "npanxx_minsort.out"; my $out_cnt = "npanxx_cntsort.out"; my $debug_out = "Test.debug"; open IN, "/bin/gunzip -c $in |" or die "IN: $!\n"; open OUT_MIN, ">", "$out_min" or die "OUT_MIN: $!\n"; open OUT_CNT, ">", "$out_cnt" or die "OUT_CNT: $!\n"; open DEBUG, ">", "$debug_out" or die "DEBUG: $!\n"; print "Processing $in...\n"; $total = 0; while () { chomp($_); next unless m/^{.*$/; my $min = (split ',')[1]; my $npanxx = substr($min, 0, 6); push (@{$list{$npanxx}}, $min); #LogToFile("Test.out", "$_ -> $min & $npanxx\n"); $counts{$npanxx} += 1; $total++; } print "$_ $counts{$_}\n" for (sort keys %counts); print "Total: $total\n"; print "Generating Flat Files...\n"; foreach $key (sort keys %counts) { print OUT_MIN "$key $counts{$key}\n"; } `echo "Total: $total" >> npanxx_minsort.out`; foreach $key (sort { $counts{$a} <=> $counts{$b} } keys %counts) { printf OUT_CNT "%-7s %s\n", $key, $counts{$key}; } `echo "Total: $total" >> npanxx_cntsort.out`; sub LogToFile { my ($file, $msg) = @_; my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $year += 1900; $mon += 1; if ($sec <= 9) { $sec = "0" . $sec; } if ($min <= 9) { $min = "0" . $min; } if ($hour <= 9) { $hour = "0" . $hour; } if ($mon <= 9) { $mon = "0" . $mon; } if ($mday <= 9) { $mday = "0" . $mday; } my $stamp = $year . "/" . $mon . "/" . $mday . " " . $hour . ":" . $min . ":" . $sec; my $str = "[" . $stamp . "] " . $msg; open FILE, ">>", $file; print FILE $str; close FILE; }