The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts 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 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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-26-2008
Registered User
 

Join Date: Nov 2005
Posts: 27
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.
Reply With Quote
Forum Sponsor
  #2  
Old 01-26-2008
Registered User
 

Join Date: Jan 2008
Posts: 328
What have you tried so far?
Reply With Quote
  #3  
Old 01-27-2008
jaduks's Avatar
Registered User
 

Join Date: Aug 2007
Location: Assam,India
Posts: 146
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
//Jadu
Reply With Quote
  #4  
Old 01-28-2008
Registered User
 

Join Date: Nov 2005
Posts: 27
Dear Jadu,

Thank u ! it is working.

Thanks you again,

Nayanajith.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:55 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0