#!/bin/bash

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

INPUT="$1"

# extract only sending/sent lines, remove unneeded data
# then combine start/end/lines
# print hash, start time, end time
echo "Block Hash,Send Start Time,Send End Time"
cat $INPUT | sed -n '/Sending/ {s/\[\([-: 0-9]*\)\] .*Sending: \([0-9A-F]*\).*/START,\1,\2/; p}; /Sent/ { s/\[\([-: 0-9]*\)\] .*Sent: \([0-9A-F]*\).*/END,\1,\2/; p }' \
	| sed -n 'N; s/\n/,/; p' \
	| awk -F ',' '{print $3","$2","$5}'
