In the below awk I am trying to skip the header, extract the number between each : and , in $2, and then print $1 and the count of $2, and put the header back in the output. My current output seems to be be duplicating each line and printing the line as is. The input may have empty columns in each line but it will always be tab-delimited. Thank you :).
awk
awk 'BEGIN{FS=OFS="\t"}; NR>1 {gsub(/:,/,"",$2); {count[$2]++} print $1,$count} FNR>1' file
also tried:
awk -F'\t' '{gsub(/:,/,"",$2); {count[$2]++}
END{print "id","string";
print $1,count}}' file | column -t
file tab-delimited
id string
a1a B:80,V:2,Z:0
b2b B:100,V:1,Z:3
current tab-delimited
a1a
a1a B:80,V:2,Z:0
b2b
b2b B:100,V:1,Z:3
desired tab-delimited
id sting
a1a 82
b2b 104