|
|
|
|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
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- |
| Sponsored Links |
|
|
|
|||
|
Hello,
I am amazed of how smooth the code is ...can you explain a little in words what is the logic of the line: max[$1] = !($1 in max) ? $2 : ($2 > max[$1]) ? $2 : max[$1] Thanks. Last edited by gio001; 02-11-2009 at 04:39 PM.. |
|
|||
|
wow vgers...
amazing solution, and amazing explaination. thank u so much! |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to sort a file and then print similar lines once | shira | Shell Programming and Scripting | 6 | 01-27-2009 01:22 PM |
| Sort, group rows | patrykxes | Shell Programming and Scripting | 6 | 01-06-2009 02:28 PM |
| awk help required to group output and print a part of group line and original line | rajan_san | Shell Programming and Scripting | 5 | 10-27-2008 09:16 AM |
| Sort cmd to get GROUP BY? | RacerX | UNIX for Dummies Questions & Answers | 6 | 10-16-2008 08:40 AM |
| PHP & MySQL: sort desending and print | perleo | Shell Programming and Scripting | 1 | 09-02-2003 12:50 PM |