Awk, highest and lowest value of a column


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Awk, highest and lowest value of a column
# 8  
Old 07-11-2013
That works very good, thank you Yoda!Smilie
To give you an impression, the list is a sample of a cfd simulation.
So I get the x , y -components of the profile and the velocity.
Now I can compute the mean value of the profile!!Smilie
# 9  
Old 07-16-2013
The idea is that the line 1 value is both in and max, and the comparison is only on lines 2-$, but your code does both on all lines. Others used the null variable load as a signal of the first line. For best speed, you want the edge activities like that to be efficiently avoided on other lines, and awk is very fast at line number checks. Now, if the data is not on every line, then you need some way to deal with startup. One solution is to set max to -2gig (int min) and min to int max. The first couple lines should load real values. Just remember that while we want to avoid checking for both min and max on later lines, the first line is both min and max, so if it was assigned to max but not min, and was actually the min, or vice versa, it would be lost. I suppose the clean and clear way to treat the first different is to have a flag variable initially 0 but set to 1 after the first value is min and max.
# 10  
Old 09-05-2013
Awk, highest and lowest value of a column Reply to Thread

Hi Yoda;

I wonder if I could use this script for a similar task.
Because, I need also to extract name present in a third column for the selected highest or lowest value.

Code:
a  1  aa
a  3  ab
a  5  ac
b  4  ba
b  2  bc
b  6  bb
c  1  ca
c  4  cb
c  3  cc

I wonder if I could create a file like this for example for highest values:

Code:
a  5  ac
b  6  bb
c  4  cb

Thanks

Quote:
Originally Posted by Yoda
Here is another awk approach:
Code:
awk '
        {
                if ( $1 in L )
                {
                        L[$1] = L[$1] > $2 ? $2 : L[$1]
                        H[$1] = H[$1] < $2 ? $2 : H[$1]
                }
                else
                {
                        L[$1] = $2
                        H[$1] = $2
                }
        }
        END {
                for ( k in L )
                        print k, L[k], H[k]
        }
' file

# 11  
Old 09-05-2013
a) Please create a new thread for your new problem
b) Why don't you give it a shot yourself and then post it for problem analysis (should problems arise)? Hint: if max($1) found, keep $3 in an array as well.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print whole line with highest value from one column

Hi, I have a little issue right now. I have a file with 4 columns test0000002,10030010330,c_,218 test0000002,10030010330,d_,202 test0000002,10030010330,b_,193 test0000002,10030010020,c_,178 test0000002,10030010020,b_,170 test0000002,10030010330,a_,166 test0000002,10030010020,a_,151... (3 Replies)
Discussion started by: Ebk
3 Replies

2. AIX

Print whole line with highest value from one column

Hi, I have a little issue right now. I have a file with 4 columns test0000002,10030010330,c_,218 test0000002,10030010330,d_,202 test0000002,10030010330,b_,193 test0000002,10030010020,c_,178 test0000002,10030010020,b_,170 test0000002,10030010330,a_,166 test0000002,10030010020,a_,151... (2 Replies)
Discussion started by: Ebk
2 Replies

3. Shell Programming and Scripting

Sort from highest to lowest number

Hi Guys, I am looking for a way to sort the output below from the "Inuse" count from Highest to Lowest. Is it possible? Thanks in advance. user1 0.12 0.06 0 0.12 User Inuse Pin Pgsp Virtual Unit:... (4 Replies)
Discussion started by: jaapar
4 Replies

4. Shell Programming and Scripting

Find lines with matching column 1 value, retain only the one with highest value in column 2

I have a file like: I would like to find lines lines with duplicate values in column 1, and retain only one based on two conditions: 1) keep line with highest value in column 3, 2) if column 3 values are equal, retain the line with the highest value in column 4. Desired output: I was able to... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

5. Shell Programming and Scripting

top 10 highest and lowest percentile from a column

Hi, I want to extract the the top 10 and lowest 10 percentile for a column of values. For example in column 2 for this file: JOE 1 JAY 5 JAM 6 JIL 8 JIB 4 JIH 3 JIG 2 JIT 7 JAM 9 MAR 10 The top 10 lowest will be: JOE 1 and the top 10 highest will be: (2 Replies)
Discussion started by: kylle345
2 Replies

6. Shell Programming and Scripting

Selecting lowest and highest values in columns 1 and 2, based on subsets in column 3

Hi, I have a file with the following columns: 361459 447394 CHL1 290282 290282 CHL1 361459 447394 CHL1 361459 447394 CHL1 178352861 178363529 AGA 178352861 178363529 AGA 178363657 178363657 AGA Essentially, using CHL1 as an example. For any line that has CHL1 in... (2 Replies)
Discussion started by: hubleo
2 Replies

7. UNIX for Dummies Questions & Answers

Print line with highest value from one column

Hi everyone, This is my first post, but I have already received a lot of help from the forums in the past. Thanks! I've searched the forums and my question is very similar to an earlier post entitled "Printing highest value from one column", which I am apparently not yet allowed to post a... (1 Reply)
Discussion started by: dliving3
1 Replies

8. Shell Programming and Scripting

trying to make an AWK code for ordering numbers in a column from least to highest

Hi all, I have a large column of numbers like 5.6789 2.4578 9.4678 13.5673 1.6589 ..... I am trying to make an awk code so that awk can easily go through the column and arrange the numbers from least to highest like 1.6589 2.4578 5.6789 ....... can anybody suggest, how can I do... (5 Replies)
Discussion started by: ananyob
5 Replies

9. UNIX for Dummies Questions & Answers

Printing highest value from one column

Hi, I have a file that looks like this: s6 98 s6 91 s6 56 s5 32 s5 10 s5 4 So what I want to do is print only the highest value for each value in the column: So the file will look like this: s6 98 s5 32 Thanks (4 Replies)
Discussion started by: phil_heath
4 Replies

10. Shell Programming and Scripting

Perl ? - How to find and print the lowest and highest numbers punched in by the user?

. . . . . . (3 Replies)
Discussion started by: some124one
3 Replies
Login or Register to Ask a Question