awk to log transform on matrix file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk to log transform on matrix file
# 1  
Old 02-28-2013
awk to log transform on matrix file

Hi Friends,

I have an input matrix file like this

Code:
    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

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

# 2  
Old 02-28-2013
What does "apply" mean? What do you want to do to your data?
# 3  
Old 02-28-2013
Not sure If I understood your requirement, is this what you are trying to do?
Code:
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

# 4  
Old 03-01-2013
Post output example.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Transform columns to matrix

The following code transform the matrix to columns. Is it possible to do it other way around ( get the input from the output) ? input y1 y2 y3 y4 y5 x1 0.3 0.5 2.3 3.1 5.1 x2 1.2 4.1 3.5 1.7 1.2 x3 3.1 2.1 1.0 4.1 2.1 x4 5.0 4.0 6.0 7.0 1.1 output x1 y1 0.3 x2 y1 1.2 x3... (1 Reply)
Discussion started by: quincyjones
1 Replies

2. Shell Programming and Scripting

How to sum the matrix using awk?

input A1 B1 A2 B2 0 0 1 1 1 0 0 1 0 1 1 0 1 1 1 1 Output label A1 B1 A2 B2 A1 2 1 1 2 B1 1 2 2 1 A2 1 2 3 2 B2 2 1 2 3 Ex: The number of times that A1 and B1 row values are both 1 should be printed as output. The last row of A1 and B1 in the input match by having 1 in both... (4 Replies)
Discussion started by: quincyjones
4 Replies

3. Shell Programming and Scripting

Add a number all the the values and log transform them using awk

Hi, is it possible to add a number to all the values in a file and log transform them using awk. thanx in advance input name c1 c2 c3 c4 r1 0 0.2 0.3 0.4 r2 0 0 0 1 r3 1 0 0 0 r4 0 0 1 ... (1 Reply)
Discussion started by: quincyjones
1 Replies

4. Shell Programming and Scripting

how to rearrange a matrix with awk

Hi, every one. I have two files ,one is in matrix like this, one is a list with the same data as the matrix. AB AE AC AD AA AF SA 3 4 5 6 4 6 SC 5 7 2 8 4 3 SD 4 6 5 3 8 3 SE 45 ... (5 Replies)
Discussion started by: xshang
5 Replies

5. Shell Programming and Scripting

Converting to matrix-like file using AWK

Hi, Needs for statistics, doing converting Here is a sample file Input : 1|A|17,94 1|B|22,59 1|C|56,93 2|A|63,71 2|C|23,92 5|B|19,49 5|C|67,58 expecting something like that Output : 1|A|17,94|B|22,59|C|56,93 2|A|63,71|B|0|C|23,92 5|A|0|B|19,49|C|67,58 (11 Replies)
Discussion started by: fastlane3000
11 Replies

6. Shell Programming and Scripting

how to calculate all pairwise distances in two dimensions and transform them into a matrix

Hello to all, I am very new in the shell scripting and I need help. I have data for several individuals in several rows followed by a tag and by 5 values per row, with the name of the individual in the first column, e.g.: IND1 H1 12 13 12 15 14 IND2 H2 12 12 15 14 14 IND3 H1 12 15... (2 Replies)
Discussion started by: Bemar
2 Replies

7. UNIX for Dummies Questions & Answers

How to log transform a text file?

How can I log transform (log 2) a text file which is a single column of numbers? (4 Replies)
Discussion started by: evelibertine
4 Replies

8. Shell Programming and Scripting

awk? adjacency matrix to adjacency list / correlation matrix to list

Hi everyone I am very new at awk but think that that might be the best strategy for this. I have a matrix very similar to a correlation matrix and in practical terms I need to convert it into a list containing the values from the matrix (one value per line) with the first field of the line (row... (5 Replies)
Discussion started by: stonemonkey
5 Replies

9. UNIX for Dummies Questions & Answers

Using awk to log transform a column in a tab-delimited text file?

How do I use awk to log transform the fifth column of a tab-delimited text file? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

10. UNIX for Dummies Questions & Answers

Use awk to log transform

Hello. I'm trying to use the awk command to convert certains fields to lgo base 2, not base 10. I'm trying command lines like: awk '$2 $5 $7 {print log(2)($2), log(2)($5), $7) filein.txt > fileout.txt I'm trying to make a deadline. Thanks for helping a newbie. Here's some fresh karma... (1 Reply)
Discussion started by: jmzcal
1 Replies
Login or Register to Ask a Question