BEGIN { FS=OFS="^" } { arr[$1] = ($1 in arr) ? arr[$1] "," $3 : $3 } END { for (i in arr) print i OFS "~", arr[i] }