![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | 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. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Monkcast #12: IBM HW group OEMs Solaris to chagrin of SW group & a ... - ZDNet.com bl | iBot | UNIX and Linux RSS News | 0 | 08-17-2007 04:30 PM |
| Count No of Records in File without counting Header and Trailer Records | guiguy | Shell Programming and Scripting | 2 | 06-07-2007 12:15 PM |
| find and group records in a file | thumsup9 | UNIX for Advanced & Expert Users | 20 | 04-19-2007 05:04 PM |
| Select records based on search criteria on first column | shashi_kiran_v | UNIX for Dummies Questions & Answers | 2 | 12-02-2005 01:49 PM |
| entry in /etc/group too long - problem using sudo with %group | poli | SUN Solaris | 4 | 12-21-2004 09:50 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Column sum group by uniq records Reply to Thread
getting below o/p..missed some values in last post
PORT;PID;TOTAL port1;p1;500 port2;p2;0 |
|
||||
|
This is what I get:
Code:
$ cat file
PORT; ID; TOTAL
port1;p1;100000
port2;p2;5000
port1;p1;500
$
$
$ awk 'BEGIN{FS=OFS=";"}
NR==1{print;next}
{a[$1";"$2]+=$3}
END{for(i in a)print i, a[i]}' file
PORT; ID; TOTAL
port2;p2;5000
port1;p1;100500
$
$
|
|
||||
|
Column sum group by uniq records Reply to Thread
HI Franklin,
Thanks a lot. It works....using nawk /usr/bin/nawk 'BEGIN{FS=OFS=";"}NR==1{print;next}{a[$1";"$2]+=$3}END{for(i in a)print i, a[i]}' file Much appreciated. Cheers, Sandeep Quote:
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|