#!/usr/bin/gawk -f BEGIN { FS=OFS="," } NF==15 { for (i=1; i<=15; i++) a[i]=$i; } NF==3 { printf($1","$2",-"); for (i=1; i<=15; i++) { target="-"i"-"; if (index($3,target)!=0) printf(a[i]"-"); } printf("\n"); #printf($4"\n"); }