awk - from arrays to lower triangular matrix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk - from arrays to lower triangular matrix
# 1  
Old 04-26-2010
awk - from arrays to lower triangular matrix

Hi,

I have to reshape some ascii files. I have many ascii files that have collapsed the lower triangular of my matrix into row. I simply want to convert them back to the proper matrix form. So, my current data looks like this:

Code:
11 21 22 31 32
33 41 42 43 44
...

This is five columns of data for an 88x88 matrix. And I want to make it look like this:

Code:
11,.,.,.,.,.,.,.,.,.,.,.,. (...88 columns)
21,22,.,.,.,.,.,.,.,.,.,.
31,32,33,.,.,.,.,.,.,.,.
41,42,43,44,.,.,.,.,.,.
51,52,53,54,55,.,.,.,.
61,62,63,64,65,66,.,.
...
(88 rows)

I want to use awk for this, but really am a novice (and a social scientist). I suspect this is simple, but am at a loss with writing the algorithim in awk.
Any help will be hugely appreciated.

Thanks very much.
--VH

Last edited by vgersh99; 04-26-2010 at 06:13 PM.. Reason: code tags, please!
# 2  
Old 04-27-2010
Try...
Code:
paste -s file1|gawk '{for(x=1;x<=n;x++)for(y=1;y<=n;y++)printf (y<=x?$(++c):".") (y==n?ORS:",")}' n=88

# 3  
Old 04-29-2010
Thanks

That set me up perfectly. After some tinkering, I found my solution.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk: get upper and lower bound per group

Hi all, I've data as: 22 51018157 51018157 exonic CHKB nonsynonymous SNV 22 51018204 51018204 exonic CHKB nonsynonymous SNV 22 51018428 51018428 exonic CHKB nonsynonymous SNV 22 51018814 51018814 ... (4 Replies)
Discussion started by: genome
4 Replies

2. Shell Programming and Scripting

Lower to upper..tr + awk ?

I have a file that has a pattern 2 lines, blanktwo line If encountering the first line, the 2nd line need to be converted to UPPERCASE...or...conver the 2nd line after ablank into uppercase Is there a 'tr' function in awk..(probably the best tool over sed) ? i.e. ......................... (6 Replies)
Discussion started by: stevie_velvet
6 Replies

3. Shell Programming and Scripting

Awk: Storing string in array(triangular form)

I have a string like below. Now i want to split this string like below and put the value in the array using awk. I am able to do it using bash but getting no clue for doing it in awk O/P A=0 A=01 A=014 A=0143 A=01438 A=014387 A=0143876 A=01438765 A=014387650 ... (7 Replies)
Discussion started by: siramitsharma
7 Replies

4. Shell Programming and Scripting

Find and copy files with field lower than a value, awk?

Hi all! I have 10.000 files having generally this format: text text text text num text num text num text text text GAP number text text text num text num text num RMS num text num text num text num ... what I want is to copy the files if the GAP number is lower than a value e.g. <100... (5 Replies)
Discussion started by: phaethon
5 Replies

5. Shell Programming and Scripting

Lower triangular matrix

Hi, I was wondering if there is a way of using awk to extract the lower or upper triangular matrix from a symmetric matrix. Say I have this matrix: $ cat data: 1 0 9 6 7 9 0 8 2 8 9 0 9 2 6 9 4 3 6 8 9 6 9 4 7 9 4 9 9 7 9 0 3 4 7 9 I am trying to do two things. Result 1: 0 9 2 6 8... (4 Replies)
Discussion started by: iconig
4 Replies

6. 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

7. Shell Programming and Scripting

Summing up a matrix using awk

Hi there, If anyone can help me sorting out this small task would be great. Given a matrix like the following: 100 3 3 3 3 3 ... 200 5 5 5 5 5 ... 400 1 1 1 1 1 ... 500 8 8 8 8 8 ... 900 0 0 0 0... (5 Replies)
Discussion started by: JRodrigoF
5 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. Programming

Triangular window

I want to code a triangular window in an array. The array size is an odd number and indices start from 1. For example Having the number of elements N = 13 The middle position 7, the value will be 1.0 Then things decrease to zero using a rectangular variation. Having problem how to code it. (2 Replies)
Discussion started by: kristinu
2 Replies

10. Shell Programming and Scripting

Printing 1st column to lower case using awk

I want to print the 1st field in a comma seperated file to lower case and the rest the case they are. I tried this nawk -F"," '{print tolower($0)}' OFS="," file this converts whole line in to lower case i just want the first column to be converted. The below doesnt work because in... (11 Replies)
Discussion started by: pinnacle
11 Replies
Login or Register to Ask a Question