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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sum the value in each column for repeat sequence under $1

Status
Not open for further replies.

demis001

Programmer
Aug 18, 2008
94
US
I want to add respective column for repeat item on $1. If there is no repeat sequence on $1, I want the exact count in each col. Please would you help me guys!
----------------------------------------------------------
data

Name a b c d e f g h
GGGACGG 2 0 7 10 2 0 4 0
GGGAGGG 0 0 4 26 8 3 0 0
GGGAGGG 61 0 51 50 79 0 55 25
GGGAGTA 0 0 2 6 11 0 0 0
Result
Name a b c d e f g h
GGGACGG 2 0 7 10 2 0 4 0
GGGAGGG 61 0 55 76 87 3 55 25
GGGAGTA 0 0 2 6 11 0 0 0
 
A starting point:
Code:
awk '
NR==1{print;next}
{x[$1];for(i=1;i<9;++i)t[$1,i]+=$(i+1)}
END{for(r in x){printf "%s",r;for(i=1;i<9;++i)printf "\t%s",t[r,i];printf "\n"}}
' data > Result

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top