Want to add those that have the same minute in a file

Hi All,

Need your help on how i can sum up the values. I have a file that contains the count and the time. I wanted to add up all the first column having the same datestamp. Please see below.

INPUT

1721    2015-12-26 00:01
1440    2015-12-26 00:02
1477    2015-12-26 00:02
411     2015-12-26 00:02
1204    2015-12-26 00:06
4413    2015-12-26 00:07
1389    2015-12-26 00:08
2013    2015-12-26 00:08
1441    2015-12-26 00:11
1439    2015-12-26 00:12
1310    2015-12-26 00:13
1650    2015-12-26 00:13
2275    2015-12-26 00:16
1549    2015-12-26 00:17
1469    2015-12-26 00:17
1289    2015-12-26 00:18
8504    2015-12-26 00:21
1357    2015-12-26 00:22
1346    2015-12-26 00:22
1283    2015-12-26 00:22
40      2015-12-26 00:22
2672    2015-12-26 00:26
1537    2015-12-26 00:27
3121    2015-12-26 00:27
4355    2015-12-26 00:28
93      2015-12-26 00:28
2300    2015-12-26 00:31
1378    2015-12-26 00:32
4953    2015-12-26 00:32
2742    2015-12-26 00:33
460     2015-12-26 00:33
1784    2015-12-26 00:36
2636    2015-12-26 00:37
2254    2015-12-26 00:37
56      2015-12-26 00:37
5624    2015-12-26 00:42
3356    2015-12-26 00:42
2230    2015-12-26 00:42
686     2015-12-26 00:43
5012    2015-12-26 00:46
1423    2015-12-26 00:47
1063    2015-12-26 00:47
716     2015-12-26 00:47
2869    2015-12-26 00:51
1474    2015-12-26 00:52
1408    2015-12-26 00:52
4587    2015-12-26 00:52
1660    2015-12-26 00:57
3223    2015-12-26 00:57
1149    2015-12-26 00:58
1912    2015-12-26 00:58
3467    2015-12-26 01:01
4683    2015-12-26 01:02
1197    2015-12-26 01:02
1296    2015-12-26 01:02
581     2015-12-26 01:06
1635    2015-12-26 01:07
3245    2015-12-26 01:07
4879    2015-12-26 01:08
1578    2015-12-26 01:12
1678    2015-12-26 01:12
1495    2015-12-26 01:13
1415    2015-12-26 01:13
2134    2015-12-26 01:16
1663    2015-12-26 01:17
1338    2015-12-26 01:17
674     2015-12-26 01:18
2066    2015-12-26 01:21

OUPUT

1721	2015-12-26 00:01
3328	2015-12-26 00:02
1204	2015-12-26 00:06
4413	2015-12-26 00:07
3402	2015-12-26 00:08
1441	2015-12-26 00:11
1439	2015-12-26 00:12
2960	2015-12-26 00:13
2275	2015-12-26 00:16
3018	2015-12-26 00:17
1289	2015-12-26 00:18
8504	2015-12-26 00:21
4026	2015-12-26 00:22
2672	2015-12-26 00:26
4658	2015-12-26 00:27
4448	2015-12-26 00:28
2300	2015-12-26 00:31
6331	2015-12-26 00:32
3202	2015-12-26 00:33
1784	2015-12-26 00:36
4946	2015-12-26 00:37
11210	2015-12-26 00:42
686	2015-12-26 00:43
5012	2015-12-26 00:46
3202	2015-12-26 00:47
2869	2015-12-26 00:51
7469	2015-12-26 00:52
4883	2015-12-26 00:57
3061	2015-12-26 00:58
3467	2015-12-26 01:01
7176	2015-12-26 01:02
581	2015-12-26 01:06
4880	2015-12-26 01:07
4879	2015-12-26 01:08
3256	2015-12-26 01:12
2910	2015-12-26 01:13
2134	2015-12-26 01:16
3001	2015-12-26 01:17
674	2015-12-26 01:18
2066	2015-12-26 01:21

Please help.

Thanks,
Ernie

Please, try:

awk '{a[$2 FS $3] += $1} END{for (i in a){print a OFS  i}}' OFS="\t" ernesto.input | sort -k2 > ernesto.output
awk '{ x[$2" "$3] += $1 } END { for (i in x) {printf("%s\t%s\n", x, i)} }' <your_data_file_name> | sort -k2,3

A Perl version to try:

perl -ne '@k=split /\s+/, $_, 2; $r{$k[1]} += $k[0]; END{for(sort keys %r){print "$r{$_}\t$_"}}' ernesto.input > ernesto.output

You could also try:

awk '
last && last != $2 FS $3 {
	print	sum, last
}
last != $2 FS $3 {
	last = $2 FS $3
	sum = 0
}
{	sum += $1
}
END {	print sum, last
}' OFS="\t" file

and avoid the need for the sort .

As always, with any of these awk suggestions, if you're using a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk or nawk .