Extracting rows and columns in a matrix based on condition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting rows and columns in a matrix based on condition
# 1  
Old 06-18-2013
Extracting rows and columns in a matrix based on condition

Hi I have a matrix with n rows and m columns like below example. i want to extract all the pairs with values <200.

Input
Code:
     A    B      C     D     
  A  100  206  51   300
  B  206  100  72   48
  C  351  22  100   198
  D  13  989  150   100

Output format
Code:
A,A:200
A,C:51
B,B:100
B,C:72
..........
D,D:100

# 2  
Old 06-18-2013
Quote:
Originally Posted by anurupa777
Hi I have a matrix with n rows and m columns like below example. i want to extract all the pairs with values <200.

Input
Code:
     A    B      C     D     
  A  100  206  51   300
  B  206  100  72   48
  C  351  22  100   198
  D  13  989  150   100

Output format
Code:
A,A:200
A,C:51
B,B:100
B,C:72
..........
D,D:100

Please post relevant information always. It will be very helpful

Try

Code:
awk 'NR==1{split($0,A)} 
     NR>1{for(i=2;i<=NF;i++){if($i<200){print $1","A[i-1]":"$i}}}' file

Regards,

pamu
This User Gave Thanks to pamu For This Post:
# 3  
Old 06-18-2013
Ya ill take care of that
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to ignore multiple rows based on a condition

All, I have a text file(Inputfile.csv) with millions of rows and 100 columns. Check the sample for 2 columns below. Key,Check A,1 A,2 A, A,4 B,0 B,1 B,2 B,3 B,4 .... million rows. My requirement is to delete all the rows corresponding to all the keys which ever has at least one... (4 Replies)
Discussion started by: ks_reddy
4 Replies

2. Shell Programming and Scripting

Columns to Rows - Transpose - Special Condition

Hi Friends, Hope all is well. I have an input file like this a gene1 10 b gene1 2 c gene2 20 c gene3 10 d gene4 5 e gene5 6 Steps to reach output. 1. Print unique values of column1 as column of the matrix, which will be a b c (5 Replies)
Discussion started by: jacobs.smith
5 Replies

3. Shell Programming and Scripting

Convert rows to columns based on condition

I have a file some thing like this: GN Name=YWHAB; RC TISSUE=Keratinocyte; RC TISSUE=Thymus; CC -!- FUNCTION: Adapter protein implicated in the regulation of a large CC spectrum of both general and specialized signaling pathways GN Name=YWHAE; RC TISSUE=Liver; RC ... (13 Replies)
Discussion started by: raj_k
13 Replies

4. Shell Programming and Scripting

Sum of range of rows and columns in matrix

Hi all, I have a large matrix of 720 x 25. I want to get sum of range of rows and columns. Like, I need sum of all columns and row number 2 to 21, then leaving 22nd row, again sum of all columns and row number 23 to 42 again leaving 43rd row and then sum of 44th to 63. Means I want to add all... (4 Replies)
Discussion started by: CAch
4 Replies

5. UNIX for Dummies Questions & Answers

Extracting rows from a text file based on the values of two columns (given ranges)

Hi, I have a tab delimited text file with multiple columns. The second and third columns include numbers that have not been sorted. I want to extract rows where the second column includes a value between -0.01 and 0.01 (including both numbers) and the first third column includes a value between... (1 Reply)
Discussion started by: evelibertine
1 Replies

6. Shell Programming and Scripting

extracting lines based on condition and copy to another file

hi i have an input file that contains some thing like this aaa acc aa abc1 1232 aaa abc2.... poo awq aa abc1 aaa aaa abc2 bbb bcc bb abc1 3214 bbb abc3.... bab bbc bz abc1 3214 bbb abc3.... vvv ssa as abc1 o09 aaa abc4.... azx aaq aa abc1 900 aqq abc19.... aaa aa aaaa abc1 899 aa... (8 Replies)
Discussion started by: anurupa777
8 Replies

7. Shell Programming and Scripting

Extract values from a matrix given the rows and columns

Hi All, I have a huge (and its really huge!) matrix about 400GB in size (2 million rows by 1.5 million columns) . I am trying to optimize its space by creating a sparse representation of it. Miniature version of the matrix looks like this (matrix.mtx): 3.4543 65.7876 54.564 2.12344... (4 Replies)
Discussion started by: shoaibjameel123
4 Replies

8. UNIX for Dummies Questions & Answers

Extracting rows from a text file based on the first column

I have a tab delimited text file where the first column can take on three different values : 100, 150, 250. I want to extract all the rows where the first column is 100 and put them into a separate text file and so on. This is what my text file looks like now: 100 rs3794811 0.01 0.3434... (1 Reply)
Discussion started by: evelibertine
1 Replies

9. Shell Programming and Scripting

Extracting columns from a matrix and storing each column in a separate file

Hi All, I have a huge matrix file consisting some some millions rows and 6000 columns. The contents are just floating point numbers in the matrix. I want to extract each column (i.e. 6000 of them) and store each column in a separate file. For example, 1.dat will consist of elements from column... (4 Replies)
Discussion started by: shoaibjameel123
4 Replies

10. Shell Programming and Scripting

awk to select rows based on condition on column

I have got a file like this 003ABC00281020091005000100042.810001 ... (8 Replies)
Discussion started by: Maruti
8 Replies
Login or Register to Ask a Question