Append the output data horizontally

Hi experts

i have a simple script that fetches the count from different servers and inserts ahead of server name like below

servera,1
serverb,25
serverc,35

what i want to do is now when i run this script next day i want that output to be next to the earlier one like below and if possible u would to insert date as well on which date what was the count

servera,1,15
serverb,25,10
serverc,35,5

Have a look at the join utility.

Can You Please share what you have tried.

Hope you are looking for something like this.

$ cat f1
servera,1,2
serverb,25,30
serverc,35,45
$ cat f2
servera,15
serverb,10
serverc,5
$ awk -F',' '{if(NR == FNR) {ar[$1]=$0;next} print ar[$1]","$2}' f1 f2
servera,1,2,15
serverb,25,30,10
serverc,35,45,5
$

If the input files are sorted you can use

join -t',' -j 1 f1 f2

Hi ranjithpr

It looks like your solution will work fine for me.. I will implement it today and will post again the results...

thanks again for alll the guys for your contribution

---------- Post updated 07-31-09 at 03:37 AM ---------- Previous update was 07-30-09 at 10:09 PM ----------

Hi

after running below

$ awk -F',' '{if(NR == FNR) {ar[$1]=$0;next} print ar[$1]","$2}' f1 f2
servera,1,2,15
serverb,25,30,10
serverc,35,45,5
$

i get the output something like this

,1,2,
,25,30,10
,35,45
,15
,10
,5

and also its not reflecting in any file it shows shows on screen

If the result of your script is in 'file1' and the master file your maintaining is 'master_file'

below commands can be used append the data of file1 to master_file

$ awk -F',' 'NR==FNR {ar[$1]=$0;next} 
            {  if($1 in ar) {  print ar[$1] "," $2;delete ar[$1] } 
                else print $0
            } 
            END { for (i in ar) print ar }' master_file file1 > master_file.tmp

$ mv master_file.tmp master_file