Skip to main content
deleted 45 characters in body
Source Link
glenn jackman
  • 88.5k
  • 16
  • 124
  • 179

Using GNU awk

gawk -F '[=;]' '
    NR == 1 {for (i=1; i<NF; i+=2) keys[$i]}
    {for (i=1; i<NF; i+=2) value[$i][NR]values[$i][NR] = $(i+1)}
    END {
        PROCINFO["sorted_in"] = "@ind_str_asc"
        for (key in keysvalues) printf "%s\t", key
        print ""
        for (line=1; line<=NR; line++) {
            for (key in keysvalues) printf "%s\t", value[key][line]
            print ""
        }
    }
' filename
AC      AC_AFR  AC_AMR  AC_Adj  AC_EAS  AC_FIN  AC_Het  
126     0       0       126     120     0       112 
12683   4578    559     12680   2104    501     91966   

I'm using 2 field separator characters here, so all the odd-numbered fields are the keys, and all the even-numbered fields are the values.

Using GNU awk

gawk -F '[=;]' '
    NR == 1 {for (i=1; i<NF; i+=2) keys[$i]}
    {for (i=1; i<NF; i+=2) value[$i][NR] = $(i+1)}
    END {
        PROCINFO["sorted_in"] = "@ind_str_asc"
        for (key in keys) printf "%s\t", key
        print ""
        for (line=1; line<=NR; line++) {
            for (key in keys) printf "%s\t", value[key][line]
            print ""
        }
    }
' filename
AC      AC_AFR  AC_AMR  AC_Adj  AC_EAS  AC_FIN  AC_Het  
126     0       0       126     120     0       112 
12683   4578    559     12680   2104    501     91966   

I'm using 2 field separator characters here, so all the odd-numbered fields are the keys, and all the even-numbered fields are the values.

Using GNU awk

gawk -F '[=;]' '
    {for (i=1; i<NF; i+=2) values[$i][NR] = $(i+1)}
    END {
        PROCINFO["sorted_in"] = "@ind_str_asc"
        for (key in values) printf "%s\t", key
        print ""
        for (line=1; line<=NR; line++) {
            for (key in values) printf "%s\t", value[key][line]
            print ""
        }
    }
' filename
AC      AC_AFR  AC_AMR  AC_Adj  AC_EAS  AC_FIN  AC_Het  
126     0       0       126     120     0       112 
12683   4578    559     12680   2104    501     91966   

I'm using 2 field separator characters here, so all the odd-numbered fields are the keys, and all the even-numbered fields are the values.

Source Link
glenn jackman
  • 88.5k
  • 16
  • 124
  • 179

Using GNU awk

gawk -F '[=;]' '
    NR == 1 {for (i=1; i<NF; i+=2) keys[$i]}
    {for (i=1; i<NF; i+=2) value[$i][NR] = $(i+1)}
    END {
        PROCINFO["sorted_in"] = "@ind_str_asc"
        for (key in keys) printf "%s\t", key
        print ""
        for (line=1; line<=NR; line++) {
            for (key in keys) printf "%s\t", value[key][line]
            print ""
        }
    }
' filename
AC      AC_AFR  AC_AMR  AC_Adj  AC_EAS  AC_FIN  AC_Het  
126     0       0       126     120     0       112 
12683   4578    559     12680   2104    501     91966   

I'm using 2 field separator characters here, so all the odd-numbered fields are the keys, and all the even-numbered fields are the values.