convert data into matrix- awk

yes exactly.
I need the count when I run the command1 and then the second command should normalize. The output should be the same matrix format as before.

Hi,

Try this one with your new requirement.

You have to store the below code in check.awk file.

check.awk
 
#! /usr/bin/awk
{
        f1[$3]=1;
        f2[$2]=1;
        if(chk1[$1] != $1 )
        {
                klist++;
                chk1[$1]=$1;
        }
        if(chk[$3"^"$2] != $1)
        {
                a[$3"^"$2]++;
                chk[$3"^"$2]=$1;
        }
}
END{
        ORS="";
        print "      ";
        for(j in f2)
        {
                print j" ";
                c++;
                if(c>5)
                {
                        print " ";
                }
        }
        print "\n";
        for(i in f1)
        {
                print i;
                for(k in f2)
                {
                        l=i"^"k;
                        if(a[l] == "")
                        {
                                print "   0    ";
                        }
                        else
                        {
                                a[l]=(a[l]/klist)*100;
                                print "   "a[l]"   ";
                        }
                }
                print "\n";
        }
}

Running procedure for this awk file,

awk -f check.awk Input_File

Cheers,
Ranga:)

2 Likes