unique entry add values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting unique entry add values
# 1  
Old 04-24-2012
unique entry add values

Hi,

I have a file with 3 columns

Code:
ABC 3 1
ABC 5 1
XYZ 4 2
DEF 3  2
DEF 4  1
DEF 6  1
MNO 5 5
JKL 3  2
JKL 4  2
PQR 12 1

For each unique entry in column 1 I want to add values in column 2 and column3

o/p
Code:
ABC 8 2
XYZ 4 2
DEF 13 4
MNO 5 5
JKL 7 4
Pqr 12 1

Thanks,
# 2  
Old 04-24-2012
Code:
$ awk '{a[$1]+=$2;b[$1]+=$3}END{for (i in a) print i,a[i],b[i]}' file
JKL 7 4
ABC 8 2
PQR 12 1
XYZ 4 2
MNO 5 5
DEF 13 4

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Code to get unique values

Hello All, I am trying to write a script which returns me clientID,programId,userID indicated in bold from the below log files.Log file is having many such data , iam just presenting sample . Sample Log file. hostname 1525867288264 UA:MP:EP491418 http-nio-8080-exec-11 ERROR Get Price... (13 Replies)
Discussion started by: nextStep
13 Replies

2. UNIX for Beginners Questions & Answers

Find unique values but only in column 1

Hi All, Does anyone have any suggestions/examples of how i could show only lines where the first field is not duplicated. If the first field is listed more than once it shouldnt be shown even if the other columns make it unique. Example file : 876,RIBDA,EC2 876,RIBDH,EX7 877,RIBDF,E28... (4 Replies)
Discussion started by: mutley2202
4 Replies

3. UNIX for Dummies Questions & Answers

Removing rows that contain non-unique column entry

Background: I have a file of thousands of potential SSR primers from Batch Primer 3. I can't use primers that will contain the same sequence ID or sequence as another primer. I have some basic shell scripting skills, but not enough to handle this. What you need to know: I need to remove the... (1 Reply)
Discussion started by: msatseqs
1 Replies

4. Shell Programming and Scripting

calculating unique strings values

Hi, Im looking for a script which will calculate the unique strings column 2 & 3 values in a log as mentioned in example eg:- bag 12 12 bag 18 15 bags 15 13 bags 15 14 blazer 24 24 blazer 33 32 boots 19 15 Result should be:- bag 30 27 bags 30 27... (9 Replies)
Discussion started by: Paulwintech
9 Replies

5. Shell Programming and Scripting

Script to update Property Entry Values

Hi All, I'm Raghavendra. I have a very urgent requirement to develop a Shell Script which will allow to use variables in a property file as demonstarted below var1=UNIX var2=LINUX var3=WINDOWS var4=$var1,$var2 var5=$var3 Could you please help me to develop a shell script which can... (2 Replies)
Discussion started by: raghavstunner
2 Replies

6. Shell Programming and Scripting

print unique values of a column and sum up the corresponding values in next column

Hi All, I have a file which is having 3 columns as (string string integer) a b 1 x y 2 p k 5 y y 4 ..... ..... Question: I want get the unique value of column 2 in a sorted way(on column 2) and the sum of the 3rd column of the corresponding rows. e.g the above file should return the... (6 Replies)
Discussion started by: amigarus
6 Replies

7. UNIX for Dummies Questions & Answers

Extract Unique Values from file

Hello all, I have a file with following sample data 2009-08-26 05:32:01.65 spid5 Process ID 86:214 owns resources that are blocking processes on Scheduler 0. 2009-08-26 05:32:01.65 spid5 Process ID 86:214 owns resources that are blocking processes on Scheduler 0. 2009-08-26... (5 Replies)
Discussion started by: simonsimon
5 Replies

8. UNIX Desktop Questions & Answers

Fetching unique values from file

After giving grep -A4 "feature 1," <file name> I have extracted the following text feature 1, subfeat 2, type 1, subtype 5, dump '30352f30312f323030392031313a33303a3337'H -- "05/01/2009 11:30:37" -- -- ... (1 Reply)
Discussion started by: shivi707
1 Replies

9. Shell Programming and Scripting

Getting Unique values in a file

Hi, I have a file like this: Some_String_Here 123 123 123 321 321 321 3432 3221 557 886 321 321 I would like to find only the unique values in the files and get the following output: Some_String_Here 123 321 3432 3221 557 886 I am trying to get this done using awk. Can someone please... (5 Replies)
Discussion started by: Legend986
5 Replies

10. Shell Programming and Scripting

to retrieve unique values

Hi all, I have a 10.txt file. In this file 2 words are present by name Active and Inactive and these words are repeated 7000 times. I want to take the unique 2 words from this 7000 lines. Thanks Mahalakshmi.A (3 Replies)
Discussion started by: mahalakshmi
3 Replies
Login or Register to Ask a Question