awk to find the max


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk to find the max
# 8  
Old 04-08-2013
Quote:
Originally Posted by sathyaonnuix
@Franklin,

Rather retrieving the entire line, I just want to print the column1 with comma separated.

Code:
# awk -F, 'NR==FNR{if($3 > m){m=$3}next}$3==m' file file
XYZf,23,29,5
XYZz,23,29,5

Try:
Code:
awk -F, 'NR==FNR{if($3>m){m=$3}next}$3==m{s=s?s FS $1:$1}END{print s}' file file

This User Gave Thanks to Franklin52 For This Post:
# 9  
Old 04-08-2013
its works, thanks Franklin. can you explain how file file works in the code.
# 10  
Old 04-08-2013
Quote:
Originally Posted by sathyaonnuix
its works, thanks Franklin. can you explain how file file works in the code.
awk reads the file twice. The condition NR==FNR is true when awk reads the file the first time.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

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