nawk -F'|' ' NR==1 $1!="H" && $1!="T" $1=="T" {tot+=$2} END { print "T" OFS tot}' OFS='|' file1 file2