-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtxns
More file actions
37 lines (36 loc) · 932 Bytes
/
Copy pathtxns
File metadata and controls
37 lines (36 loc) · 932 Bytes
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
#!/usr/bin/env -S gawk -f
# Converts sorted postings to transactions using pta format
# On stdin expects postings sorted by date, payee, price asc
# so that postings are grouped together
# transaction is created every time running balance is near zero <0.0001
{
balance += +$2
if (date) {
if (date == $1) {
date = $1
$1 = ""
}
if (common == $4)
$4 = ""
} else {
date = $1
$1 = ""
common = $4
$4 = ""
}
gsub(/^[[:space:]]*|[[:space:]]*$/, "") # strip spaces on ends
gsub(/[[:space:]]+/, " ") # collapse spaces
lines[i++] = $0
if (-0.0001 < balance && balance < 0.0001) {
# print transactions
printf "%s %s\n", date, common
for (j in lines) {
print lines[j]
}
printf "\n"
# reset array
i = 0
delete lines
date = ""
}
}