Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Awk, highest and lowest value of a column Post 302831345 by bjoern456 on Wednesday 10th of July 2013 06:18:48 PM
Old 07-10-2013
@DGPickett:
Do you mean something like this:
Code:
awk' {min[$1]=$2 , max[$1]=$2
         if  ($2 >= max) max=$2
         else if ($2 <= min) min = $2}
END {for (x in min) print x, min[x], max[x]}
' list

It doesnt work, but I dont know how to do it better right now..


@RudiC:
I tried your code, but when I try lists like this I fail.
Code:
3 -1
3 1
4 -1
4 5
4 7
4 -7

Thanks!
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
ADD(2)								System Calls Manual							    ADD(2)

NAME
add, sub, mul, div, raddp, rsubp, rmul, rdiv, rshift, inset, rcanon, eqpt, eqrect, ptinrect, rectinrect, rectXrect, rectclip, Dx, Dy, Pt, Rect, Rpt - arithmetic on points and rectangles SYNOPSIS
#include <u.h> #include <libc.h> #include <libg.h> Point add(Point p, Point q) Point sub(Point p, Point q) Point mul(Point p, int a) Point div(Point p, int a) Rectangle raddp(Rectangle r, Point p) Rectangle rsubp(Rectangle r, Point p) Rectangle rmul(Rectangle r, int a) Rectangle rdiv(Rectangle r, int a) Rectangle rshift(Rectangle r, int a) Rectangle inset(Rectangle r, int n) Rectangle rcanon(Rectangle r) int eqpt(Point p, Point q) int eqrect(Rectangle r, Rectangle s) int ptinrect(Point p, Rectangle r) int rectinrect(Rectangle r, Rectangle s) int rectXrect(Rectangle r, Rectangle s) int rectclip(Rectangle *rp, Rectangle b) int Dx(Rectangle r) int Dy(Rectangle r) Point Pt(int x, int y) Rectangle Rect(int x0, int y0, int x1, int y1) Rectangle Rpt(Point p, Point q) DESCRIPTION
The functions Pt, Rect and Rpt construct geometrical data types from their components. These are implemented as macros. Add returns the Point sum of its arguments: Pt(p.x+q.x, p.y+q.y). Sub returns the Point difference of its arguments: Pt(p.x-q.x, p.y-q.y). Mul returns the Point Pt(p.x*a, p.y*a). Div returns the Point Pt(p.x/a, p.y/a). Raddp returns the Rectangle Rect(add(r.min, p), add(r.max, p)); rsubp returns the Rectangle Rpt(sub(r.min, p), sub(r.max, p)). Rmul returns the Rectangle Rpt(mul(r.min,a), mul(r.max,a)); Rdiv returns the Rectangle Rpt(div(r.min,a), div(r.max,a)). Rshift returns the rectangle r with all coordinates either left-shifted or right-shifted by a, depending on whether a is positive or nega- tive, respectively. Inset returns the Rectangle Rect(r.min.x+n, r.min.y+n, r.max.x-n, r.max.y-n). Rcanon returns a rectangle with the same extent as r, canonicalized so that min.x <= max.x, and min.y <= max.y. Eqpt compares its argument Points and returns 0 if unequal, 1 if equal. Eqrect does the same for its argument Rectangles. Ptinrect returns 1 if p is a point within r, and 0 otherwise. Rectinrect returns 1 if all the pixels in r are also in s, and 0 otherwise. RectXrect returns 1 if r and s share any point, and 0 otherwise. Rectclip clips in place the Rectangle pointed to by rp so that it is completely contained within b. The return value is 1 if any part of *rp is within b. Otherwise, the return value is 0 and *rp is unchanged. The functions Dx and Dy give the width (x) and height (y) of a Rectangle. They are implemented as macros. SOURCE
/sys/src/libg SEE ALSO
graphics(2) ADD(2)
All times are GMT -4. The time now is 04:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy