The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 02-11-2009
m4rco- m4rco- is offline
Registered User
  
 

Join Date: Feb 2009
Posts: 7
awk - sort, then print the high value for each group

Hi @ all

I'm trying to achive to this problem,

I've a 2-column composed file as the following:

192.168.1.2 2
192.168.1.3 12
192.168.1.2 4
192.168.1.4 3
cpc1-swan1-2-3-cust123.swan.cable.ntl.com 4
192.168.1.3 5
192.168.1.2 10
192.168.1.4 8
cpc1-swan1-2-3-cust123.swan.cable.ntl.com 8

and i would this kind of output :

192.168.1.2 10
192.168.1.3 12
192.168.1.4 8
cpc1-swan1-2-3-cust123.swan.cable.ntl.com 8

I'm trying to use this methodology :

Code:
awk  '{  a[$NF]=$2; if ( a[$NF] >= max[$NF] ) max[$NF]=a[$NF] } END { for ( item in a )  print item,max[item] }'

but i'm not sure this is the right way....

Thanks you all in advance!!!

m4rco-