Sponsored Content
Full Discussion: awk to find the max
Top Forums Shell Programming and Scripting awk to find the max Post 302791157 by sathyaonnuix on Monday 8th of April 2013 04:47:01 AM
Old 04-08-2013
awk to find the max

Experts,
Here is my question.
I have got file like below

Code:
# cat file
XYZb,24,26,6
XYZc,24,26,6
XYZe,24,25,5
XYZf,23,29,5
XYZi,16,25,5
XYZj,24,26,7
XYZn,17,23,4
XYZz,23,29,5

Now, I want to print the line's Column1[delimitor is ,] whose Column 3 is the max of all.

My code is
Code:
awk -F',' 'BEGIN {max = 0;} {if ($3>max) {max=$3;server=$1}} END {print server}' file

But, If there are more than 1 row contain the same max value, my snippet is printing only the last one. Please help.

Here my expected output is XYZf,XYZz.

PS: I want to get this accomplished with awk
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

find max number

Hi, i have a file with numbers in it and i was wondering if there's a script i could use to find the max number and have that printed to a new file? example a.txt 18 26 47 34 27 so find the max number in a.txt and print it to b.txt. Thanks! (17 Replies)
Discussion started by: moonbaby
17 Replies

2. Shell Programming and Scripting

Find max number in a set

Is there a simple way of calculating the max number in a set of variables, so a=1 b=3 c=6 d=30 something that says e=max($a, $b, $c, $d) I've found a way to do it using: a="1" b="3" c="5" d="50" if ; then t=$a else (3 Replies)
Discussion started by: unclecameron
3 Replies

3. Shell Programming and Scripting

How to find max value in a tabular data?

FILE_NAME VER TYPE DELETED_DATE CREATED_DATE SIZE LOCATION hello 1 d 2010-08-09 2010-08-09 4096 /home/xxxxx/project/ hello 2 d 2010-08-09 2010-08-09 4096 /home/xxxxx/project/ hello 3 d 2010-08-09 2010-08-09 4096 /home/xxxxx/project/ hello 4 d 2010-08-09 2010-08-09 4096 /home/xxxxx/project/ ... (4 Replies)
Discussion started by: classic
4 Replies

4. Shell Programming and Scripting

Find min.max value if matching columns found using AWK

Input_ File : 2 3 4 5 1 1 0 1 2 1 -1 1 2 1 3 1 3 1 4 1 6 5 6 6 6 6 6 7 6 7 6 8 5 8 6 7 Desired output : 2 3 4 5 -1 1 4 1 6 5 6 8 5 8 6 7 (3 Replies)
Discussion started by: vasanth.vadalur
3 Replies

5. Shell Programming and Scripting

to find min and max value for each column!

Hello Experts, I have got a txt files which has multiple columns, I want to get the max, min and diff (max-min) for each column in the same txt file. Example: cat file.txt a 1 4 b 2 5 c 3 6 I want ouput like: cat file.txt a 1 4 b 2 5 c 3 6 Max 3 6 Min 1 4 Diff 2 2 awk 'min=="" ||... (4 Replies)
Discussion started by: dixits
4 Replies

6. Shell Programming and Scripting

Find max value problem

I have a file about cpu load like this (the first column is time, the second column is cpu load): 11:34:01 0.10 11:34:37 0.05 11:35:13 0.03 11:35:59 0.06 11:38:00 0.02 11:38:09 0.17 11:39:48 0.06 I need to find the max value of the second column so I write the script as follows max=0... (5 Replies)
Discussion started by: muffle
5 Replies

7. Shell Programming and Scripting

Find the numeric value in a string and then check the max. value

hi, i have a string " 00000069 ThreadMonitor W WSVR0606W: Thread "WebContainer : 43|null" (00000069) was previously rep orted to be hung but has completed. It was active for approximately 47533430 milliseconds. There is/are 43 thread(s) in tot al in the server that still may be hung." ... (4 Replies)
Discussion started by: lovelysethii
4 Replies

8. UNIX for Dummies Questions & Answers

Using awk to find max and printing entire line

Hi folks, I am very new to awk. I have what is probably a very simple question. I'm trying to get the max value of column 1, but also print column 2. My data looks like this: 0.044|2000-02-03 14:00:00 5.23|2000-02-03 05:45:00 5.26|2000-02-03 11:15:00 0|2000-02-01 18:30:00 So in this case... (2 Replies)
Discussion started by: amandarobe
2 Replies

9. Shell Programming and Scripting

awk script to find min and max value

I need to find the max/min of columns 1 and 2 of a 2 column file what contains the special character ">". I know that this will find the max value of column 1. awk 'BEGIN {max = 0} {if ($1>max) max=$1} END {print max}' input.file But what if I needed to ignore special characters in the... (3 Replies)
Discussion started by: ncwxpanther
3 Replies

10. Shell Programming and Scripting

Find Max value of line and print

I need to find the max value of all columns except the 1st column and print the answer along with the 1st column. Input 123xyz 0 0 1 2 0 0 0 0 0 0 0 234xyz 0 0 0 0 0 0 0 0 0 0 0 345xyz 0 0 1 0 0 0 ... (8 Replies)
Discussion started by: ncwxpanther
8 Replies
MOD_GEARMAN_WORKER(8)					  System Administration Utilities				     MOD_GEARMAN_WORKER(8)

NAME
mod_gearman_worker - Agent that runs active checks from a gearman queue DESCRIPTION
usage: worker [ --debug=<lvl> ] [ --logmode=<automatic|stdout|syslog|file> ] [ --logfile=<path> ] [ --debug-result ] [ --help|-h ] [ --daemon|-d ] [ --config=<configfile> ] [ --server=<server> ] [ --dupserver=<server> ] [ --hosts ] [ --services ] [ --eventhandler ] [ --hostgroup=<name> ] [ --servicegroup=<name> ] [ --do_hostchecks ] [ --min-worker=<nr> ] [ --max-worker=<nr> ] [ --max-age=<sec> ] [ --timeout ] [ --encryption=<yes|no> ] [ --key=<string> ] [ --keyfile=<file> ] [ --min-worker=<nr> ] [ --max-worker=<nr> ] [ --idle-timeout=<nr> ] [ --max-jobs=<nr> ] [ --spawn-rate=<nr> ] [ --fork_on_exec ] [ --show_error_output ] [ --enable_embedded_perl ] [ --use_embedded_perl_implicitly ] [ --use_perl_cache ] [ --p1_file ] [ --workaround_rc_25 ] see README for a detailed explaination of all options. SEE ALSO
The Mod Gearman documentation is available in /usr/share/doc/mod-gearman/README.html mod_gearman_worker 1.3.6-1 July 2012 MOD_GEARMAN_WORKER(8)
All times are GMT -4. The time now is 04:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy