I don't know why but this code below used to perfom crosstab query (see crosstab with AWK question)returns
mismatch (with printing duplicate lines) if I use gawk interpretor instead awk. My gawk version is: GNU Awk 3.1.4.
what's wrong ?
BEGIN {
FS=OFS=";"
}
{
if ( !($2 in cols) ) cols[$2]=++colsN
tag[$1 , $2] = $3
}
END {
# inverting the assoviative array - make it an indexed array
for ( i in cols)
cols[cols] = i
printf("tag%s", OFS)
for(i=1; i<= colsN; i++){
printf("%s%s", cols, (i<colsN) ? OFS : "\n")
}
for( i in tag) {
split(i, iA, SUBSEP)
printf("%s%s", iA[1], OFS)
for(i=1; i <= colsN; i++) {
idx=iA[1] SUBSEP cols
printf("%s%s", (idx in tag) ? tag[idx] : "0", (i<colsN) ? OFS : "\n")
if ( idx in tag) delete tag[idx]
}
}
}
mismatch (with printing duplicate lines) if I use gawk interpretor instead awk. My gawk version is: GNU Awk 3.1.4.
what's wrong ?
BEGIN {
FS=OFS=";"
}
{
if ( !($2 in cols) ) cols[$2]=++colsN
tag[$1 , $2] = $3
}
END {
# inverting the assoviative array - make it an indexed array
for ( i in cols)
cols[cols] = i
printf("tag%s", OFS)
for(i=1; i<= colsN; i++){
printf("%s%s", cols, (i<colsN) ? OFS : "\n")
}
for( i in tag) {
split(i, iA, SUBSEP)
printf("%s%s", iA[1], OFS)
for(i=1; i <= colsN; i++) {
idx=iA[1] SUBSEP cols
printf("%s%s", (idx in tag) ? tag[idx] : "0", (i<colsN) ? OFS : "\n")
if ( idx in tag) delete tag[idx]
}
}
}