-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwallet.awk
59 lines (50 loc) · 937 Bytes
/
wallet.awk
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/awk -f
BEGIN {
tot = 0;
start = 1;
mTot = 0;
mOut = 1; # montly and total output
mCurr = "";
error = 0;
if (ARGC == 2) {
mOut = 0; # only tot output
} else if (ARGC < 2 || (ARGC == 3 && ARGV[2] != "--monthly")) {
print "Usage: ./inout.awk filename [--monthly]"
ARGC = 1;
ARGV[1] = ARGV[2] = "";
error = 1;
exit 1;
} else {
# --monthly
ARGV[2] = "";
ARGC--;
}
}
/^[+-].*[0-9]/ {
tot += $1;
mTot += $1;
}
mOut == 1 && /^[^+-]/ {
if (start == 0) {
if (mTot > 0)
mTot = "+"mTot;
print " Total monthly money aside: "mTot" euros"
mTot = 0;
} else if (start == 1) {
start = 0;
}
mCurr = $0;
print $mCurr":"
}
END {
if (!error) {
if (mTot > 0)
mTot = "+"mTot;
if (mOut == 1)
print " Total monthly money aside: "mTot" euros"
if (tot > 0)
tot = "+"tot
printf("\n\n\nTOTAL status: ")
print tot" euros"
}
}