plus values from two files differient fields.

Hi Everyone,

I have two files:
filea:

Sun Jun 21 14:37:56 2009         1       2       3
Sun Jun 21 11:47:16 2009         2       3       4

fileb:

Sun Jun 21 14:37:56 2009         1       2       3
Sun Jun 21 11:47:17 2009         33      44       55

The output is filec:

Sun Jun 21 14:37:56 2009         2       4       6
Sun Jun 21 11:47:16 2009         2       3       4
Sun Jun 21 11:47:17 2009         33      44       55

I know i can do:
awk '{A[$1" "$2" "$3" "$4" "$5"\t"]+=$6}END{for (i in A){print i" "A[i]}}' filea fileb
but this is just plus the field 6, how about field 7 and 8? :confused:

Thanks

If you understand the code you're using for the first column, you should be able to sum up the other columns too. Use 2 more arrays for the other columns.

Regards

Hi Frank,

i tried many ways, but failed. like

awk '{A[$1" "$2" "$3" "$4" "$5"\t"]+=$2;B[$1" "$2" "$3" "$4" "$5"\t"]+=$3}END{for (i in A){print i" "A[i]" "B[i]}}' filea fileb

awk '{A[$1" "$2" "$3" "$4" "$5"\t"]+=$2$3}END{for (i in A){print i" "A[i]" "B[i]}}' filea fileb

and others, but cannot, i think i cannot understand very well on this script. Please advice me.

Thanks

---------- Post updated at 03:28 AM ---------- Previous update was at 03:18 AM ----------

I know the way already:

awk '{A[$1" "$2" "$3" "$4" "$5"\t"]+=$6$7$8}END{for (i in A){print i" "A[i]}}' filea fileb

But the output is
Sun Jun 21 11:47:17 2009 334455
Sun Jun 21 14:37:56 2009 246
Sun Jun 21 11:47:16 2009 234

how to become below?
Sun Jun 21 11:47:17 2009 33 44 55
Sun Jun 21 14:37:56 2009 2 4 6
Sun Jun 21 11:47:16 2009 2 3 4

Try this:

awk '{
A[$1" "$2" "$3" "$4" "$5]+=$6;
B[$1" "$2" "$3" "$4" "$5]+=$7;
C[$1" "$2" "$3" "$4" "$5]+=$8}
END{for (i in A){print i, A,B,C}}' filea fileb

Thanks,:b:

awk '{A[$1" "$2" "$3" "$4" "$5"\t"]+=$6}{B[$1" "$2" "$3" "$4" "$5"\t"]+=$7}{C[$1" "$2" "$3" "$4" "$5"\t"]+=$8}END{for (i in A){print i" "A[i]" "B[i]" "C[i]}}' filea fileb