awk to log transform on matrix file

Hi Friends,

I have an input matrix file like this

    Col1 Col2 Col3 Col4
R1 1 2 3 4
R2 4 5 6 7
R3 5 6 7 8

I would like to consider only the numeric values without touching the column header and the row header.

I looked up on the forum's search, and I found this. But, I donno how to apply it to my particular dataset

awk '{print log($2)/log(2)}'

What does "apply" mean? What do you want to do to your data?

Not sure If I understood your requirement, is this what you are trying to do?

awk ' NR == 1 {
                print
} NR > 1 {
                for (i=1; i<=NF; i++)
                {
                        if($i ~ /^[0-9]+$/)
                        {
                                $i = log($i) / log(2)
                                printf "%.2f ", $i
                        }
                        else
                                printf "%s ", $i
                }
                printf "\n"
} ' file

Post output example.