Finding the highest value(in negative)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding the highest value(in negative)
# 1  
Old 08-16-2011
Question Finding the highest value(in negative)

Hi all,

I have a simple problem. I have given an example of the problem below.

There are 4 space-delimited columns.



Code:
2655    96    IA    -0.8179 
2655    96    IA    -0.9144 
2655    96    CPU    -0.4275
2655    96    RMA    -0.3407 
2655    96    IA    -0.9373
2655    96    eugene    -0.8338 
2655    96    CPU    -0.9469

Result should look like the following, where the forth column has only the highest values for the particular item in column 3. Generally I could use awk for this purpose, but I am confused as how to deal with the negative values.


Code:
2655    96    IA    -0.8179 
2655    96    CPU    -0.4275 
2655    96    RMA    -0.3407 
2655    96    eugene    -0.8338

Please help. Thanks.

---------- Post updated at 12:55 AM ---------- Previous update was at 12:52 AM ----------

a solution in awk will be like:

Code:
awk '{if ($4 > a[$1" "$2" "$3])a[$1" "$2" "$3]=$4}END{for (i in a) print i, a[i]}' file

but this does not work for the negative values
# 2  
Old 08-16-2011
Code:
awk '
!a[$1" "$2" "$3] || $4 > a[$1" "$2" "$3] { a[$1" "$2" "$3] = $4 } 
END { for (i in a) print i, a[i] }
' INPUTFILE

This User Gave Thanks to yazu For This Post:
# 3  
Old 08-16-2011
woo hoo!!! such a quick reply and works too Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Selecting highest value within a range

Within millions of lines of data, there are perhaps 20 "spikes" that are very narrow. I want only the highest value from each spike within a range of 10 rows. Possible? My data looks like this, 8 columns of integers, millions of rows. There are clear spikes when you graph columns. ... (6 Replies)
Discussion started by: markymarkg123
6 Replies

2. Shell Programming and Scripting

Script read highest value

Hi All, Can someone help steer me to the simplest approach to write a script that reads the second column of a csv file and returns the highest value. example file: DATE,QUANTITY Mon Apr 30 01:56:00 2012,42 Mon Apr 30 02:24:00 2012,72 Mon Apr 30 02:56:00 2012,102 Mon Apr 30 02:59:00... (3 Replies)
Discussion started by: dekker74
3 Replies

3. Shell Programming and Scripting

Print the key with highest value

print the key with highest value input a 10 a 20 a 30 b 2 b 3 b 1 output a 30 b 3 (9 Replies)
Discussion started by: quincyjones
9 Replies

4. Shell Programming and Scripting

Bash, finding highest number in another file

i have a problem i am working on and am completely new to bash commands. I writing a script to read another file and output the max and Min number in the script. I must use variables to output the max and min numbers. grades = file with numbers in them. This is what i got so far. Thank You in... (3 Replies)
Discussion started by: ctanner10126
3 Replies

5. Shell Programming and Scripting

Extract the highest number out

Hi Gurus, I've using HPUX B.11.23 U ia64 with shell = sh. I've been having some problem get the highest number of this script. Actually I wanted to get the highest number from this listing (TEST123 data and based on this highest number, there will be email being sent out. For example,... (6 Replies)
Discussion started by: superHonda123
6 Replies

6. Shell Programming and Scripting

Finding the most positive and negative value and defining its position

Hi, I have a file that looks like this: Jake 2 3 4 6 4 3 -2 -1 Jerry 1 2 3 2 1 7 -6 -1 Timmy -1 -4 -5 -8 9 3 1 I want to find the most positive and negative value for each row and also define its position (based on column #) So the output would look... (7 Replies)
Discussion started by: gisele_l
7 Replies

7. Shell Programming and Scripting

Finding line with highest number in a file

Hi All, My file looks some thing like this, File 1: - A 10 B 30 C 5 D 25 E 72 F 23 now my requirement is to find the line with highest number in it, i;e the result should be E 72 Thanks in Advance (1 Reply)
Discussion started by: balu_puttaganti
1 Replies

8. UNIX for Dummies Questions & Answers

sort with highest wc

Hi :) I'm a unix beginner and i've recently got an assignment to write up a script to print the most common IP address that made requests from a webserver. I'm really lost in this one...and if someone could pls tell me where to start i'll be really greatful ! thanx (1 Reply)
Discussion started by: ymf
1 Replies

9. 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
Login or Register to Ask a Question