Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
Showing results for 
Search instead for 
Did you mean: 

Adding the field in 3 files

Go to solution
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.

The same names are appering in the 2nd and 3rd file with same order.
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

Re: Adding the field in 3 files


# 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:


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.