Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk problem+edit file

Status
Not open for further replies.

nomanoma

Programmer
Apr 6, 2006
24
BA
Hello I have one problem..

I have fileA:

value1 1
value2 3
value3 4
value1 9
value2 5
value5 5
value1 2
value4 1
...
..
...
..


I wanted file like this:

fileB:
value1 12 3
value2 3 2
value3 4 4
value4 1 1
value5 5 1


where I do not have douplicates anymore and second column is sum of values for each value and 3. column is number each same record shows in file

for example in fileA 3 times value1 records is shown..
vale2 is 2 times shown in fileA and 2 solumn in fileB meand that total values for value1 is 12


any hints?
 
A starting point:
awk '{a[$1]+=$2;++b[$1]}END{for(i in a)print i,a,b}' fileA

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top