Finding minimum value out of specific rows


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding minimum value out of specific rows
# 1  
Old 08-16-2011
Finding minimum value out of specific rows

Hi all,

I am having multiple files with the pattern given below:

Quote:
29 awh 1 hkl 5.789
29 awh 2 gyh 4.765
29 awh 3 bdf 9.654
29 awh 4 hfk 3.786
29 awh 5 lkj 8.543
.
.
30 awh 1 hkl 14.342
30 awh 2 gyh 23.543
30 awh 3 bdf 2.764
30 awh 4 hfk 4.123
30 awh 5 lkj 8.432
.
.
31 vbn 1 hkl 43.654
31 vbn 2 gyh 12.765
31 vbn 3 bdf 3.564
31 vbn 4 hfk 67.231
31 vbn 5 lkj 1.548
I need to find the minimum value of 5th column if column 1 is x and 2nd column is awh or vbn or ... (20 different strings).
the output must be like:

Quote:
29 awh 4 hfk 3.786
30 awh 3 bdf 2.764
31 vbn 5 lkj 1.548
and so on....
Kindly help me to figure out this prob....

Thanks in advance Smilie
# 2  
Old 08-16-2011
not tested...

if you have gnu grep, then grep -m is supported

Code:
 
while read str; do sort -k 4,4 -k 5,5 original_file | grep -m 1 "...$str" ; done < patternfile

# 3  
Old 08-16-2011
Code:
...sort -n -k5...

# 4  
Old 08-16-2011
Thanks itkamaraj and yazu,

the code given by both of you is showing some result having minimum values.....but it is not showing in the manner which I want.

I actually need to have the minimum value in 5th column of every commom first column:

ie, min of all rows having "29" in column 1
min of all rows having "30" in column 1
min of all rows having "31" in column 1
The output should be like :

ex:
Quote:
29 awh 4 hfk 3.786
30 awh 3 bdf 2.764
31 vbn 5 lkj 1.548
I dont want to sort it on the basis of strings in column 2 right now....
Once, I will have the entire rows containing minimum value of column 5 on the basis of 1st column, I will look for the strings in column 2.

Any help is appreciated Smilie
# 5  
Old 08-17-2011
Hi all,

I sorted my file on the basis of 1st and fifth column.....
file looks like:

Quote:
11 ASP 11 ASP 0.000000
11 ASP 12 LEU 3.837670
11 ASP 14 SER 5.061534
11 ASP 13 ALA 5.563813
11 ASP 15 LEU 6.243380
11 ASP 16 ALA 8.575789
11 ASP 17 ILE 10.225147
11 ASP 18 TYR 10.606235
11 ASP 19 SER 12.187581
12 LEU 12 LEU 0.000000
12 LEU 13 ALA 3.816566
12 LEU 11 ASP 3.837670
12 LEU 15 LEU 4.992551
12 LEU 14 SER 5.235894
12 LEU 16 ALA 5.949579
12 LEU 17 ILE 8.651156
12 LEU 18 TYR 9.742082
12 LEU 19 SER 10.292144
rows are arranged in ascending order of 1st and 5th column

Now I want to print the row containing minimum value in 5th column(i.e, top most value) if ($1 != $3) && ($3 != $1 +1) && ($3 != $1-1)

help is appreciated.....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Python: find the minimum in all rows

I am using Biopython to process an alignment in fasta format. I need to slice the sequences where there is the first stop codon. So I divided my alignment in codons and found the stop. I then found the first codon position using enumerate(). But I found the minimum for each row. However I need to... (0 Replies)
Discussion started by: Homa
0 Replies

2. UNIX for Dummies Questions & Answers

Finding difference in 1st field for rows of data

I have a file that has multiple lines, of grouped data, that typically all have the same values in the 1st field, however, I would like to search the 1st field for any differences and set a flag to use in an "if" statement to run some other routine. An example of the typical file is below,... (2 Replies)
Discussion started by: co21ss
2 Replies

3. Shell Programming and Scripting

Finding minimum maximum and average

I am trying to find the minimum maximum and average from one file which has values Received message from https://www.demandmatrix.net/app/dm/xml] in milliseconds. Received message from https://www.demandmatrix.net/app/dm/xml] in milliseconds. Received message from... (5 Replies)
Discussion started by: aroragaurav.84
5 Replies

4. Shell Programming and Scripting

Finding Minimum in a Series

I have two LARGE files of data more than 20,000 line each, file-1 and file-2, and I wish to do the following if possible: file-1 1 2 5 7 9 2 4 6 3 8 9 4 6 8 9 3 2 1 3 1 2 . . . file-2 1 2 3 2 5 7 5 7 3 7 9 4 . (5 Replies)
Discussion started by: ali2011
5 Replies

5. Shell Programming and Scripting

Extracting specific rows

Hi all..... I have a file which contains large data...like I want to print the rows starting from "pixel" till the file read the letter "TER" into a new output file.... can anyone plz help in doing this ?? (5 Replies)
Discussion started by: CAch
5 Replies

6. Shell Programming and Scripting

Finding minimum value

Hi All, I have multiple files which contains 5 columns and multiple rows..... I want to calculate the minimum value of column 5th, if column 2 is MET, till column 1 comes to the next number. Also it must skip the condition similar to 1st line where column number 1 and 3 are same and... (9 Replies)
Discussion started by: CAch
9 Replies

7. Shell Programming and Scripting

Deleting specific rows in large files having rows greater than 100000

Hi Guys, I need help in modifying a large text file containing more than 1-2 lakh rows of data using unix commands. I am quite new to the unix language the text file contains data in a pipe delimited format sdfsdfs sdfsdfsd START_ROW sdfsd|sdfsdfsd|sdfsdfasdf|sdfsadf|sdfasdf... (9 Replies)
Discussion started by: manish2009
9 Replies

8. Shell Programming and Scripting

Finding Minimum value per Row range of data

Here is an example of a file I am working with: C 4704 CB 1318 ASP 115 BGRF 1 weak 0.0% 4.33 C 4720 OD 1322 ASP 115 BGRF 1 weak 0.0% 3.71 O 4723 OD 1322 ASP 115 BGRF 1 weak 0.0% 3.48 O 4723 CG 1321 ASP 115 BGRF 1 weak 0.0% 4.34... (3 Replies)
Discussion started by: userix
3 Replies

9. Shell Programming and Scripting

Finding different rows

I have two files. They are prety much the same, except a few lines. I would like to get the differences between the two file, but only those differences and nothing more. "diff" and "sdiff" cannot seem to do it. "sdiff -s" gets close, but I still get "less than" or "greater than" signs in the... (2 Replies)
Discussion started by: dombi
2 Replies

10. Solaris

finding & replacing blank rows/spaces in a file

Can anyone help me find and replace blank rows in a file with a numeric value (ie blankrow=someTxtOrNumValue), the file is over 500,000 rows long so it would need to be the quickest way as I'll need to do this for multiple files...I would be greatfull for any suggestions....thanks sample file:... (2 Replies)
Discussion started by: Gerry405
2 Replies
Login or Register to Ask a Question