![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| 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 01:30 PM |
| Count No of Records in File without counting Header and Trailer Records | guiguy | Shell Programming and Scripting | 2 | 06-07-2007 09:15 AM |
| find and group records in a file | thumsup9 | UNIX for Advanced & Expert Users | 20 | 04-19-2007 02:04 PM |
| Select records based on search criteria on first column | shashi_kiran_v | UNIX for Dummies Questions & Answers | 2 | 12-02-2005 10:49 AM |
| entry in /etc/group too long - problem using sudo with %group | poli | SUN Solaris | 4 | 12-21-2004 06:50 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Column sum group by uniq records
Dear All,
I want to get help for below case. I have a file like this. saman 1 gihan 2 saman 4 ravi 1 ravi 2 so i want to get the result, saman 5 gihan 2 ravi 3 like this. Pls help me. Thank you. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
What have you tried so far?
|
|
#3
|
||||
|
||||
|
This can be done using associative array in awk.
Code:
$ cat nayan.out
saman 1
gihan 2
saman 4
ravi 1
ravi 2
$ awk '{arr[$1]+=$2} END {for (i in arr) {print i,arr[i]}}' nayan.out > nayan.out.tmp
$ cat nayan.out.tmp
ravi 3
saman 5
gihan 2
|
|
#4
|
|||
|
|||
|
Dear Jadu,
Thank u ! it is working. Thanks you again, Nayanajith. |
|||
| Google The UNIX and Linux Forums |