bigsh: Use gnu-unifont instead of misc-fixed on hpelite2
[sunny256-utils.git] / ep_day
blob9238524a61e1556a1fc29ff3719228ba51679eee
1 #!/usr/bin/env perl
3 #=======================================================================
4 # ep_day
5 # File ID: 524e5f42-5d39-11df-a9d4-90e6ba3022ac
6 # Samler en masse tidspunkter i epoch-format på for eksempel samme dag
7 # eller hver time. Forventer antall sekunder siden 19700101T000000Z
8 # først på linja.
9 #=======================================================================
11 use strict;
12 use warnings;
13 use Getopt::Std;
15 $| = 1;
17 our ($opt_d, $opt_h, $opt_s, $opt_w) =
18 ( 0, 0, 0, 0);
20 getopts('d:hs:w:');
22 my $Period = 0;
23 my %Data = ();
24 my $Lowest = 4_294_967_295; # Hm. Æ sei ikkje meir. 2³²-1
25 my $Highest = 0;
27 $opt_h && usage(0);
29 if (defined($ARGV[0]) && !($ARGV[0] =~ /[^0-9]/)) {
30 $Period = $ARGV[0];
31 shift;
34 if ($opt_s =~ /^\d+$/) {
35 $Period += $opt_s;
38 if ($opt_d =~ /^\d+$/) {
39 $Period += $opt_d * 86400;
42 if ($opt_w =~ /^\d+$/) {
43 $Period += $opt_w * 7*86400;
46 $Period || ($Period = 86400);
48 while (<>) {
49 if (/^(\d+)/) {
50 my $Curr = int($1/$Period);
51 $Lowest = $Curr if ($Curr < $Lowest);
52 $Highest = $Curr if ($Curr > $Highest);
53 $Data{$Curr}++;
54 } else {
55 warn("Line $.: Invalid line format");
59 for (my $Check = $Lowest; $Check < $Highest; $Check++) {
60 defined($Data{$Check}) || ($Data{$Check} = 0);
63 # @tmp_array-prosjektet er en nødløsning for å få sortert utdataene.
65 my @tmp_array = ();
67 while (my ($Num, $Val) = each %Data) {
68 push(@tmp_array, sprintf("%u\t%u\n",
69 ($Num * $Period) + int($Period / 2),
70 $Val
75 if (open(TmpFP, "| sort -n")) {
76 for (@tmp_array) {
77 print(TmpFP $_);
79 close(TmpFP);
80 } else {
81 die("Can’t open pipe: $!");
84 sub usage {
85 # {{{
86 my $Retval = shift;
87 print <<END;
89 Syntax: $0 [options] [file [more files [even more [you get the point]]]]
91 Options:
93 -d N Use N days as period
94 -n Generate data up to current time, guarantees complete periods,
95 but data values may vary when executed at different timepoints.
96 -s N Use N seconds as period
97 -w N Use N weeks as period
99 END
100 exit $Retval;
101 # }}}
104 # End of file ep_day