-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwatch
More file actions
executable file
·59 lines (46 loc) · 1.16 KB
/
watch
File metadata and controls
executable file
·59 lines (46 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/perl
# $Id: watch,v 1.1 2005/11/12 03:36:09 jonathan Exp $
use strict;
use Getopt::Std;
use Statistics::Descriptive;
# Written by Jonathan Ledlie
# jonathan@eecs.harvard.edu
##################################################
my $usage = "Usage: tail -f file | watch -f frequency -k column -w [keyword column] > result\n";
my %para = ();
getopts('f:k:w:', \%para);
my $frequency = 0;
if (defined($para{'f'})) {
$frequency = $para{'f'};
} else {
die ("Frequency required");
}
my @items = ();
my $count = 0;
while (my $line = <>) {
if (defined ($para{'w'})) {
if ($line =~ /$para{'w'}\s(\d+\.?\d*)/) {
my $item = $1;
$items[$#items+1] = $item;
#print "$line $item\n";
} else {
#print "no match $line\n";
}
} elsif (defined ($para{'k'})) {
my (@i) = split (/\s/,$line);
if (defined ($i[$para{'k'}-1])) {
$items[$#items+1] = $i[$para{'k'}-1];
}
}
$count++;
if ($count >= $frequency) {
my $stat = Statistics::Descriptive::Full->new();
$stat->add_data(@items);
my $out = printf ("%.3f %.3f %.3f",
$stat->mean(), $stat->standard_deviation(),
$stat->max());
print "$out\n";
$count = 0;
@items = ();
}
}