-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathu_w_counter.sh
More file actions
executable file
·79 lines (58 loc) · 1.8 KB
/
u_w_counter.sh
File metadata and controls
executable file
·79 lines (58 loc) · 1.8 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
if [ ! $# == 2 ]; then
echo "Dude! Invoke like this: $0 <print_all-file> <interval-in-seconds>";
exit;
fi
file=$1
interval=$2
if [[ $interval -lt 1 ]]; then
echo "Dude! Really! interval should be greater than 0"
exit
fi
start_time=$(grep -m 1 "Timestamp" $file | cut -d' ' -f6-7 | cut -d'(' -f2 | cut -d')' -f1)
finish_time=$(grep "Timestamp" $file | tail -n 1 | cut -d' ' -f6-7 | cut -d'(' -f2 | cut -d')' -f1)
finish_time=$(date -d "$finish_time" '+%m/%d/%Y %H:%M:%S')
start_line=1
numLine=$(wc -l < $file)
end_line=0
finish=false
i=1
# main program
while [[ $end_line -lt $numLine ]]; do
next_time=$(date -d "$start_time $interval seconds" '+%m/%d/%Y %H:%M:%S')
start_time=$next_time
next_time=$(echo $next_time | cut -d' ' -f2)
end_line=$(grep -n -m 1 "$next_time" $file | cut -d':' -f1)
if [[ $end_line -eq 0 ]]; then
next_time=$start_time
while [[ ($end_line -eq 0) && ($next_time < $finish_time) ]]; do
next_time=$(date -d "$next_time 1 seconds" '+%m/%d/%Y %H:%M:%S')
temp_time=$(echo $next_time | cut -d' ' -f2)
end_line=$(grep -n -m 1 "$temp_time" $file | cut -d':' -f1)
done
if [[ $end_line -eq 0 ]]; then
end_line=$numLine
finish=true;
fi
fi
tail_line=$((end_line - start_line))
start_line=$end_line
if [[ $finish = false ]]; then
let end_line--
else
let tail_line++
fi
head -n $end_line $file | tail -n $tail_line > tmp
# ---------------------------
# calling functions
# ---------------------------
n_updates=$(grep -n -c "Withdrawn Routes Length:" tmp)
n_annonce=$(grep -n -c "Withdrawn Routes Length: 0" tmp)
n_withrow=$((n_updates - n_annonce))
echo "$i: numUpdates: $n_updates | numWithdrow: $n_withrow | numAnnounce: $n_annonce"
# ---------------------------
# end of calling functin area
# ---------------------------
rm -f tmp
let i++
done