perl -e'local$/or$_=<>,s{^TABLE;(.+?)$|^COLUMN;(.+?);.*$}{$1?(($t=$1),""):"$t.$2"}mexg and print;' data.txt