#!/bin/bash

if [ -z "$1" ] || [ ! -f "$1" ]; then
	echo "Usage: $0 file"
	exit 0
fi

function convert_date() {
	date -d "$1" +"%Y-%m-%d %H:%M:%S"
}

function strip_label() {
	echo "$1" | sed 's/[A-Za-z0-9_]\+=//'
}

INPUT="$1"

echo "Block Height,Start Timestamp"
grep "Leaving block file" "$INPUT" | awk '{print $1,$8}' | while read timeUtc heights; do
	# 2022-04-28T06:32:07Z heights=0...244, 
	timeLocal="$(convert_date $timeUtc)"
	lastHeight=$(echo "$heights" | sed 's/.*\.\.\.\([0-9]\+\).*/\1/')
	let blockHeight=$lastHeight+1
	echo "$blockHeight,$timeLocal"
done

