From 5de5e987b46f6f775cade9bdc40e9a5dc795bb2a Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 20 Jul 2021 10:21:11 +0200 Subject: [PATCH] script: translate-log-to-epoch --- translate-log-to-epoch | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 translate-log-to-epoch diff --git a/translate-log-to-epoch b/translate-log-to-epoch new file mode 100755 index 0000000..830f6ee --- /dev/null +++ b/translate-log-to-epoch @@ -0,0 +1,17 @@ +#!/usr/bin/env zsh + +# this script translates hagrid's update logs from "per-day" format into "per-epoch" format. +(( $# > 0 )) || { echo "Usage: $0 logfiles.." >&2; exit 1; } + +for f in "$@"; do + integer next_epoch_time=0 + while read -r line; do + timestamp=${line%% *} + if (( timestamp >= next_epoch_time )); then + current_epoch=$(( timestamp / (1<<15) )) + next_epoch_time=$(( (current_epoch + 1) * (1<<15) )) + echo writing epoch $current_epoch + fi + echo $line >> $current_epoch + done < $f +done