#!/bin/bash
# File name from Jim is $2

echo $0 $1 $2 $3
OUTFILE="bpt$(echo ${1} | egrep -o 'ACM[12AB]{2}calTable' ).dbd"
echo "Output file will be " $OUTFILE

awk 'NR > 2 { print }' < $1 | sed 's|.*ACM:HTR:\([9210]\{3\}\):\([AB]\):\([^\.]*\).*|breaktable(ACM_HTR_\1_\2_\3) {|' | sed 's|[ ]\+\([0-9\.]\+\)[ ]\+\([0-9\.]\+\)|\t\2 \1|' | sed 's|^.\{0,3\}$|\}|' | sed '/\}/{n;s/\}//}' > $OUTFILE
#TODO: Add a '}' at the end of the file
echo '}' >> $OUTFILE