cancel
Showing results for 
Search instead for 
Did you mean: 

Adding the field in 3 files

SOLVED
Go to solution
Ankush_Me_1
Occasional Visitor

Adding the field in 3 files

I have 3 files these files contains the exactly column like this :

*******************************************
* Name H Fee(1st yr) Scholarship(1styr) *
*******************************************
Steave :7000 :5000
Mike :5000 :2000
Jhon :7000 :3000
and so on

I have simillar 2 more files which have the same columns but for 2nd year and 3rd year in 2nd and 3rd file respectively.

I want a single file which will be containing the name of the candidate ,sum of hostel fee for 3 years, sum of scholarship for three years.

Assuming:
The same names are appering in the 2nd and 3rd file with same order.
3 REPLIES
Ankush_Me_1
Occasional Visitor

Re: Adding the field in 3 files

Can any one reply mw.
How we can add up the colums of 2nd year and 3rd year to first year.
Using awk.I am try to write a shell script for that.
James R. Ferguson
Acclaimed Contributor
Solution

Re: Adding the field in 3 files

Hi:

# awk '{H[$1]+=$2;S[$1]+=$3};END{for (name in H) print name, H[name], S[name]}' file1 file2 file3 > fileout

Any number of file arguments can be passed. It doesn't matter if a name fails to appear in any file, either.

I see that you are new to the Forums. Welcome! Please see:

http://forums1.itrc.hp.com/service/forums/helptips.do?#28

Regards!

...JRF...
Ankush_Me_1
Occasional Visitor

Re: Adding the field in 3 files

Thanks a lot boss!
yeah i m new to this form.

I have customize it with accordance to my need.
But u have given a wonderful approach.

ll approach u if i ll not be able to solve any problem my self.

Thanks once again.