#! /usr/bin/gawk -f # Last edited on 2016-12-11 02:54:11 by jstolfi # Computes weekly total volumes (Wednesday to Tuesday) # for the Gemini auction. BEGIN { dtA = ""; # First date in week. nd = 0; # Number of days in week so far. vt = 0; # BTC volume in week so far. ut = 0; # USD volume in week so far. } // { gsub(/[#].*$/, "", $0); gsub(/^[ ]+/, "", $0); gsub(/[ ]+$/, "", $0); } /^[ ]*$/ { next; } /^[ ]*[!]/ { printf "! DateRange ! VolBTC ! VolUSD \n"; next; } /^[ ]*[+]/ { printf "+--+--+--\n"; next; } /[|]/ { dt = $2; # Date (ISO). vb = $4; # Volume traded on that date (BTC). pr = $6; # Auction closing price (USD/BTC). nd++; vt += vb; ut += vb*pr; if (nd == 7) { printf "| %s %s | %17.8f | %15.2f \n", dtA, dt, vt, ut; nd = 0; vt = 0; ut = 0; } else if (nd == 1) { dtA = dt; } next; } // { printf "%s:%d: ** bad line\n", FILENAME, FNR > "/dev/stderr"; exit(1); } END { printf "left over %d days with %.8f BTC (%.2f USD)\n", nd, vt, ut > "/dev/stderr"; exit(0); }