BEGIN { FS=OFS="," Count=0 } Pass==1 && NF==4 { ID[NR]=$1 uID[$1]=NR Data[NR,"lo"]=$2 Data[NR,"me"]=$3 Data[NR,"hi"]=$4 Count++; } Pass==2 && NF==2 { if ($1 in uID) { i=uID[$1] Data[i,"lo"]=$2 Data[i,"me"]=$2 Data[i,"hi"]=$2 } } Pass==2 && NF==3 { if ($1 in uID) { i=uID[$1] Data[i,"lo"]=$2 Data[i,"me"]="?" Data[i,"hi"]=$3 } } Pass==2 && NF==4 { if ($1 in uID) { i=uID[$1] Data[i,"lo"]=$2 Data[i,"me"]=$3 Data[i,"hi"]=$4 } } END { if (Pass==2) { for(i=1;i<=Count;i++) { print ID[i],Data[i,"lo"],Data[i,"me"],Data[i,"hi"] } } }