#! /bin/bash 
# Last edited on 2011-04-15 17:27:37 by stolfi

# Recomputes the time in hours (column 3 not counting the "|"s) 
# from columns 1 (date yyyy-mm-dd) and 2 (time of day HH:MM)
# Then realigns columns.

gawk \
  -v FS='|' \
  ' /^[ ]*([\#]|$)/ { print; next; }
    // { 
      gsub(/[ ]/, "", $0); 
      dt=$1; hr=$2; 
      dtx=(dt " 00 00 00"); gsub(/[\/-]/, " ", dtx);
      yr=substr(dt,1,4); dy=(yr-2011)*365 + strftime("%j", mktime(dtx));
      n=split(hr,hf,":");
      ht=hf[1]+(1.0/60.0)*hf[2]; 
      printf "%s | %s | %5.1f", dt, hr, 24*dy+ht - 1680; 
      for (i=4; i<=NF;i++) { printf " | %s", $(i); } printf "\n"; 
    } ' \
  | txtable-reformat
  
