Try and adapt the following script :
#!/usr/bin/bash
# Script File : test2.sh
# Input File : test2.txt
declare -i total frst
while IFS=, read timestamp f2 f3 frst rest
do
hour=${timestamp:11:2}
: ${prv_hour:=$hour}
if [ $hour != ${prv_hour} ]
then
echo "$hour => $total"
(( total = 0 ))
prv_hour=$hour
hour=
fi
(( total += frst ))
done < test2.txt
[ -n "$hour" ] && echo "$hour => $total"
Input File:
$ cat test2.txt
2007-05-31-0000,0,0,537,538,489,490,0,0,0,0,0,0,46,46
2007-05-31-0001,0,0,552,552,489,489,2,2,0,0,0,0,60,60
2007-05-31-0002,0,0,526,526,482,482,0,0,0,0,0,0,43,43
2007-05-31-0003,1,1,575,575,518,518,0,0,0,0,0,0,57,56
2007-05-31-0004,0,0,522,522,480,480,0,0,0,0,0,0,42,42
2007-05-31-0005,0,0,533,533,479,479,0,0,0,0,0,0,53,53
2007-05-31-0006,0,0,489,489,442,442,0,0,0,0,0,0,47,47
2007-05-31-0007,0,0,504,504,473,473,0,0,0,0,0,0,31,31
2007-05-31-0008,0,0,485,484,451,451,0,0,0,0,0,0,34,33
2007-05-31-0009,0,0,475,475,442,442,0,0,0,0,0,0,33,33
2007-05-31-0010,0,0,506,507,461,461,0,0,0,0,0,0,45,46
2007-05-31-0011,0,0,485,484,450,450,0,0,0,0,0,0,35,34
2007-05-31-0012,0,0,485,486,434,434,0,0,0,0,0,0,51,52
2007-05-31-0013,0,0,447,446,411,410,1,1,0,0,0,0,35,35
2007-05-31-0014,0,0,471,472,423,424,1,1,0,0,0,0,46,46
2007-05-31-0015,0,0,445,445,398,398,0,0,0,0,0,0,47,47
2007-05-31-0100,0,0,537,538,489,490,0,0,0,0,0,0,46,46
2007-05-31-0101,0,0,552,552,489,489,2,2,0,0,0,0,60,60
2007-05-31-0102,0,0,526,526,482,482,0,0,0,0,0,0,43,43
Execution :
$ test2.sh
01 => 8037
01 => 1615
$
Jean-Pierre.