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

Help on a simple awk prob

Status
Not open for further replies.

jmiles

ISP
May 26, 2002
1
0
0
US
I have to take a file with the format:
97865467
3
10
3
5
7
9
93689383
6
6
10
8
2
4
99836353
ect...

where the 8 didgit numberis an id number and the six numbers (on the six lines) following, are marks.

and with this file i must add up the six marks and put them next to the id number for each person so i edn up with a file looking like this:

99823634 34
99383635 50
ect...

any help on how i would go about this would be greatly appreciated

thanking you!
 

Hello, JMiles!

Please, try awk this script:


length($0) == 8 {

# print previous id and sum but not if is first row
if (NR != 1)
print id, sum

id = $0
sum = 0

}


length($0) < 8 { sum += $0 }


Awk is good choice for this problem.

Tell me, does is works.

Bye!

KP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top