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

Addition of marks

Status
Not open for further replies.

kevmullet

Technical User
Feb 12, 2002
56
GB
i need to add some column together from the following format:

960002323
01 10
02 8
03 10
04 6
05 9
06 0

i have to add the second column together to make it look like :

960002323 43

i have a number of blocks of marks (its an exam marking system)

thanks for any help
 
Here's one quick & dirty way :)

Create an awk script with the following code (lets call it marks.awk)
Code:
NR==1 {id=$1}
NF==1 && NR==1 {tot=0;id=$1}
NF==1 && NR != 1 {print id,tot;tot=0;id=$1}
NF==2 {tot+=$2}
END {print id,tot}
Then run the script against the input file using awk -f marks.awk inputfile

Greg.
 
In fact you can probably ditch the 1st line ...
Code:
NF==1 && NR==1 {tot=0;id=$1}
NF==1 && NR != 1 {print id,tot;tot=0;id=$1}
NF==2 {tot+=$2}
END {print id,tot}
Greg.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top