Finding minimum value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding minimum value
# 1  
Old 08-08-2011
Finding minimum value

Hi All,

I have multiple files which contains 5 columns and multiple rows.....

Quote:
11 MET 11 MET 0.000000
11 MET 12 ASD 3.761659
11 MET 13 IDE 5.339681
11 MET 14 AST 5.627152
11 MET 15 ARR 6.126280
11 MET 16 TUY 8.169484
12 ASD 11 MET 9.767652
12 ASD 12 ASD 0.000000
12 ASD 13 MET 10.960126
12 ASD 14 AST 13.947411
13 MET 11 MET 12.985269
13 MET 12 ASD 9.456213
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 the value in column five is zero.

the output should be:

Quote:
11 MET 3.761659
13 MET 9.456213
. MET
. MET
12 ASD 9.767652
.
.
likewise for every other string (there are total 20 different strings)



Any help is appreciated.

Thanks in advance.
# 2  
Old 08-08-2011
finding min value

Code:
nawk 'BEGIN{FS=' ';mval=$5;n=$1;i=0;val=0;}$1 !~ $3 & $2 ~ /MET/{if(n != $1){print $1 " " mval; }if($5 < mval){mval=$5}}'  ur_file_name


Cheers,
Ranga:-)
# 3  
Old 08-08-2011
hi Ranga,

Its showing an error......
Quote:
-bash: nawk: command not found
# 4  
Old 08-09-2011
Use awk instead of nawk

Cheers,
Ranga:-)
# 5  
Old 08-09-2011
Hi ranga,

awk is also showing error

Quote:
awk: cmd. line:2: BEGIN{FS=
awk: cmd. line:2: ^ unexpected newline or end of string
# 6  
Old 08-09-2011
Put your strings ALA, ASD, etc all in one file, one per line. Let's call this file 'strings'.
Then you can do:

Code:
while read aa ; do 
  awk '$2=="'$aa'" && !($1==$3 && $5==0){print}' input | sort -nk5 
done < strings

This User Gave Thanks to mirni For This Post:
# 7  
Old 08-10-2011
Hi mirni,

Ur code works well.....Smilie
but as I want to run this code on multiple files....i need to save this printed data of each file in their corresponding output file for further analyses. Iam using the following code :

Quote:
paste liist | while read line;
do
while read aa ; do
awk '$2=="'$aa'" && !($1==$3){print}' $line > $line"new"
done < strings
done
But the output file is completely blank...without any data....However, the code is giving the desired output if data is not transfered to the new output file.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

Find minimum value different from zero

Hello, I have this file file1.csv Element1;23-10-2012;1,450;1,564;1,428 Element2;23-10-2012;1,448;1,565;1,427 Element3;23-10-2012;1,453;1,570;1,424 Element4;23-10-2012;1,428;1,542;1,405 Element5;23-10-2012;1,461;;1,453 Element6;23-10-2012;1,438;1,555;1,417... (6 Replies)
Discussion started by: saba01
6 Replies

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

4. Shell Programming and Scripting

Finding minimum value out of specific rows

Hi all, I am having multiple files with the pattern given below: 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: Kindly help me to figure out this prob.... Thanks in... (4 Replies)
Discussion started by: CAch
4 Replies

5. Shell Programming and Scripting

Find the minimum value

Hi there I have generated a column containing 100.000 values. Sample: 94.971 101.468 73.120 100.601 102.329 I need to find the minimum value in this file and I must know which row it is in (no sorting). I hope you can help! Thanks! (16 Replies)
Discussion started by: cno
16 Replies

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

7. HP-UX

minimum password length

Dear frnds, how i can make the password 5chs minimum length in hp-ux 11i ? pls help regards (3 Replies)
Discussion started by: jestinabel
3 Replies

8. Shell Programming and Scripting

finding duplicate files by size and finding pattern matching and its count

Hi, I have a challenging task,in which i have to find the duplicate files by its name and size,then i need to take anyone of the file.Then i need to open the file and find for more than one pattern and count of that pattern. Note:These are the samples of two files,but i can have more... (2 Replies)
Discussion started by: jerome Sukumar
2 Replies

9. UNIX for Dummies Questions & Answers

AIX minimum requirements

What are the minimum hardware requirements to install AIX. Completely new to this. (2 Replies)
Discussion started by: boricua
2 Replies

10. UNIX for Dummies Questions & Answers

Minimum RAM

Can anyone tell me the minimum ram requirements for suse 6.1 & mdk9 please? Will they accept edo ram? (3 Replies)
Discussion started by: onestepto
3 Replies
Login or Register to Ask a Question