summaryrefslogtreecommitdiff
path: root/backomp
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2023-03-25 15:11:38 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2023-03-25 15:11:38 -0700
commitd3e52a72b19b64f3443204fe9cac44637217f30b (patch)
tree37affb3fe560dcffacdee64c99f163f5f7260bb8 /backomp
parent082e99b686143a8d7c01554277f91c21d71779ae (diff)
downloadbackomp-d3e52a72b19b64f3443204fe9cac44637217f30b.tar.gz
backomp-d3e52a72b19b64f3443204fe9cac44637217f30b.tar.xz
less repetition in awk filter
Diffstat (limited to 'backomp')
-rwxr-xr-xbackomp32
1 files changed, 14 insertions, 18 deletions
diff --git a/backomp b/backomp
index 1517ef5..37efaf5 100755
--- a/backomp
+++ b/backomp
@@ -2,37 +2,33 @@
set -e
-# FIXME: clean up repetition
! read -rd '' FILTER_AWK <<'EOF'
function flr(n, s) { return int(n / s) * s }
BEGIN {
- if (match(retain, /([*0-9]+)h/, md)) hr = md[1]
- if (match(retain, /([*0-9]+)d/, md)) dr = md[1]
- if (match(retain, /([*0-9]+)w/, md)) wr = md[1]
- if (match(retain, /([*0-9]+)m/, md)) mr = md[1]
+ split("h d w m", buckets)
+ for (i in buckets)
+ if (match(retain, "([*0-9]+)" buckets[i], md) && md[1])
+ ret[buckets[i]] = md[1]
}
{
t = mktime(gensub(/(.*\/|^)(.+)-(..)-(..)-(..)(..)(..)/,
"\\2 \\3 \\4 \\5 \\6 \\7", 1), 1)
- h = flr(t, 60*60)
- d = flr(t, 24*60*60)
- m = mktime(strftime("%Y %m", t, 1) " 01 00 00 00", 1)
- w = m + flr(t - m, 7*24*60*60)
-}
+ bt["h"] = flr(t, 60*60)
+ bt["d"] = flr(t, 24*60*60)
+ bt["m"] = mktime(strftime("%Y %m", t, 1) " 01 00 00 00", 1)
+ bt["w"] = m + flr(t - m, 7*24*60*60)
-h in hkeep || hr == "*" || hc++ < hr { hkeep[h] = $1 }
-d in dkeep || dr == "*" || dc++ < dr { dkeep[d] = $1 }
-w in wkeep || wr == "*" || wc++ < wr { wkeep[w] = $1 }
-m in mkeep || mr == "*" || mc++ < mr { mkeep[m] = $1 }
+ for (b in ret)
+ if ((b, bt[b]) in bkeep || ret[b] == "*" || bc[b]++ < ret[b])
+ bkeep[b, bt[b]] = $1
+}
END {
- for (i in hkeep) keep[hkeep[i]]++
- for (i in dkeep) keep[dkeep[i]]++
- for (i in wkeep) keep[wkeep[i]]++
- for (i in mkeep) keep[mkeep[i]]++
+ for (i in bkeep)
+ ++keep[bkeep[i]]
asorti(keep)
for (i in keep) print keep[i]